clutz
clutz copied to clipboard
Gents produces invalid TS when using aliases for string or numbers
Ran into this problem today. The following code:
/**
* @typedef {string}
*/
Foo;
/**
* @typedef {string}
*/
Bar;
/**
* @private {!Object<Foo, Bar>}
*/
var fooBar = {};
becomes:
type Foo = string;
type Bar = string;
let fooBar: {[key: Foo]: Bar} = {};
which then gives you a TS compiler error: An index signature parameter type must be 'string' or 'number'.
Ideally we know not to use Foo as the type for the key, and use string instead.
Context on why this isn't supported is here: https://github.com/Microsoft/TypeScript/issues/7374.
Seems like a weird corner case. Could you fix the originating code?