TypeScript Version:
1.8.7 (ES6 mode)
Code
type SymbolKeysGiveNumbers = { [x: symbol]: number };
Expected behavior:
Should work
Actual behavior:
Error: an index signature parameter must be 'string' or 'number'
However:
Code
let x: { [key: string]: any };
x[Symbol("abcd")] = 12;
Expected behavior:
Should not work based on the error above
Actual behavior:
Works
Conclusion
Symbol type should be allowed as an index signature parameter type as in practice it is accepted as a valid index key type. Even the error message when doing something like:
let x: { [key: string]: any };
x[true] = 1;
includes 'symbol' as a valid option:
An index expression argument must be of type 'string', 'number', 'symbol' or 'any'
TypeScript Version:
1.8.7 (ES6 mode)
Code
Expected behavior:
Should work
Actual behavior:
Error: an index signature parameter must be 'string' or 'number'However:
Code
Expected behavior:
Should not work based on the error above
Actual behavior:
Works
Conclusion
Symboltype should be allowed as an index signature parameter type as in practice it is accepted as a valid index key type. Even the error message when doing something like:includes 'symbol' as a valid option: