9

I have this:

const symbols = {
   typeMap: Symbol('type.map')
}

interface LangMap {
  [key: string]: string | true,
  golang: string,
  typescript: string,
  java: string,
  swift: string
}

export const setTypeMap = function(v: LangMap) : LangMap{
  v[symbols.typeMap] = true;
  return v;
};

I get this error:

TS2538: Type 'unique symbol' cannot be used as an index type.

enter image description here

Does anyone know what that error is about? I am on tsc version 3.1.6.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

-1

My poor workaround :

const bar: Record<any, string> = {};
const FOO = Symbol('foo');

// eslint-disable-next-line @typescript-eslint/no-explicit-any
bar[FOO as any] = 'sad';
Gnucki
  • 5,043
  • 2
  • 29
  • 44