clutz icon indicating copy to clipboard operation
clutz copied to clipboard

Gents produces invalid TS when using aliases for string or numbers

Open joelpoloney opened this issue 8 years ago • 1 comments

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.

joelpoloney avatar Apr 19 '17 00:04 joelpoloney

Seems like a weird corner case. Could you fix the originating code?

mprobst avatar Apr 19 '17 08:04 mprobst