Skip to content

Enum member used in computed property name leads to compile error when using outputted .d.ts file #19704

Closed
@dsherret

Description

@dsherret

TypeScript Version: 2.7.0-dev.20171102

Code

// test.ts
import * as ts from "typescript";

export const someVar = {
    [ts.SyntaxKind.SourceFile]: ""
};

Compile with: tsc test.ts --declaration --module commonjs

Expected behavior:

Expect the declaration file to export as it did in TS 2.5.3:

export declare const someVar: {
    [key: number]: string;
};

...or at least throw a compile error when compiling with --declaration.

Actual behavior:

export declare const someVar: {
    [ts.SyntaxKind.SourceFile]: string;
};

No compile error.

Another example

Here's another example that doesn't error with --declaration, even though I'm using a private name:

// test.ts
enum MyEnum {
    member = 0
}

export const someVar = {
    [MyEnum.member]: ""
};

// output: test.d.ts (and no compile error)
export const someVar = {
    [MyEnum.member]: string
};

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions