Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS2.7 produces illegal .d.ts files for objects with computed property names #21138

Closed
mprobst opened this issue Jan 11, 2018 · 5 comments
Closed

Comments

@mprobst
Copy link
Contributor

mprobst commented Jan 11, 2018

TypeScript Version: 2.7.0-dev.20180110

Code

export const SOME_STRING = 'api-key';
export const DEFAULTS = {
  [SOME_STRING]: 'some value',
};

Expected behavior:

Produce a valid .d.ts file.

Actual behavior:

Produces:

export declare const SOME_STRING = "api-key";
export declare const DEFAULTS: {
    [SOME_STRING]: string;
};

The declaration of [SOME_STRING]: string gives [ts] A computed property name in a type literal must directly refer to a built-in symbol.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 11, 2018

Just to clarify.. you mean illegal in previous versions of the compiler.

@mprobst
Copy link
Contributor Author

mprobst commented Jan 12, 2018

You are right. The bug I was trying to pin down is rather that you cannot create a type from DEFAULTS:

import {DEFAULTS} from './decl';
type z = typeof DEFAULTS;  // z is {}
type keys = keyof z;  // keys is never

@mprobst
Copy link
Contributor Author

mprobst commented Jan 12, 2018

This might be related to #13042?

@mhegazy
Copy link
Contributor

mhegazy commented Jan 12, 2018

You are right. The bug I was trying to pin down is rather that you cannot create a type from DEFAULTS:

import {DEFAULTS} from './decl';
type z = typeof DEFAULTS;  // z is {}
type keys = keyof z;  // keys is never

I am not seeing this locally on typescript@next:

image

@mprobst
Copy link
Contributor Author

mprobst commented Jan 16, 2018

I can repro the issue with TS2.6, but indeed not typescript@next, so seems fixed already (and we'll have to work around it for the TS2.6 migration).

@mprobst mprobst closed this as completed Jan 16, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants