Skip to content

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

Closed

Description

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

Activity

  1. weswigham commented on Oct 1, 2020

    @weswigham
    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.

  2. added
    BugA bug in TypeScript
    and removed
    Fix AvailableA PR has been opened for this issue
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Oct 1, 2020
  3. weswigham commented on Oct 1, 2020

    @weswigham
    Member

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

  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

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

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions