Closed
Description
TypeScript Version: 2.4.0
Code
In ES6 Computed Properties syntax, we are allowed to use any type as the property of an object. e.g.:
const s = Symbol()
// `[ts] A computed property name must be of type 'string', 'number', 'symbol', or 'any'.`
const awesomeObj = {
[() => {}]: 'function',
[null]: 'null',
[undefined]: 'undefined',
[s]: 'symbol',
}
console.log(Object.keys(awesomeObj)) // ["() => {}", "null", "undefined"]
Above are valid usages, but TS tips me: [ts] A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
Another non-sense restriction is we can't set symbols or any other types exclude string and number as object's indexes while we defining object interface.
--del--
// `An index signature parameter type must be 'string' or 'number'.`
interface IAwesomeObj {
[key: any]: number
}
--del--
--updated--
// `An index signature parameter type must be 'string' or 'number'.`
interface IAwesomeObj {
[key: Symbol]: number
}
--updated--
The key will eventually be string or symbol, but TS should allow us defining any types as the properties.