Skip to content

"unique symbol" is generated to multiple .d.ts files #40786

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

Closed
zoltan-mihalyi opened this issue Sep 26, 2020 · 2 comments · Fixed by #40886
Closed

"unique symbol" is generated to multiple .d.ts files #40786

zoltan-mihalyi opened this issue Sep 26, 2020 · 2 comments · Fixed by #40886
Assignees
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue

Comments

@zoltan-mihalyi
Copy link

zoltan-mihalyi commented Sep 26, 2020

TypeScript Version: 4.0.3
Search Terms:
unique symbol, declaration, .d.ts, invalid, TS4023

Code

a.ts

type AX = { readonly A: unique symbol };
export const A: AX = 0 as any;

b.ts

import { A } from './a';
export const A1 = A;

tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "rootDir": "src",
    "outDir": "lib"
  }
}

Expected behavior:
Typescript should either throw TS4023, or generate the following code for b.d.ts:

import { A } from './a';
export declare const A1: typeof A;

Actual behavior:
Typescript generates "unique symbol" to both a.d.ts and b.d.ts:

a.d.ts

declare type AX = {
    readonly A: unique symbol;
};
export declare const A: AX;
export {};

b.d.ts

export declare const A1: {
    readonly A: unique symbol;
};

Project Link:
project.zip

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Sep 29, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.0 milestone Sep 29, 2020
@weswigham
Copy link
Member

Hm. I suppose we should issue an error here? The local type from a isn't reachable in b, so we print the type anonymously; however it contains a unique symbol which, by rights, refers to a symbol in a different file; so we can't really serialize it. The only thing you could write out is something like export declare const A1: typeof A, like you propose, but our declaration emit generally doesn't write out typeof queries on its own (simply because it doesn't generalize - it'd only work for exactly declarations of the form var x = some.dotted.name, which is an odd syntactic carve-out to make for TS code), which is why it's more in-line with our normal behavior to report an error on the attempted usage of a private symbol, and require an annotation.

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 1, 2020
@weswigham weswigham added Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files and removed Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. labels Oct 1, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 1, 2020
@weswigham
Copy link
Member

In fact, the error already exists, and is simply failing to trigger due to an unfortunate bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants