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

Missing import in generated declaration file #49065

Closed
vilicvane opened this issue May 11, 2022 · 3 comments · Fixed by #49221
Closed

Missing import in generated declaration file #49065

vilicvane opened this issue May 11, 2022 · 3 comments · Fixed by #49221
Assignees
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@vilicvane
Copy link
Contributor

Bug Report

🔎 Search Terms

emitted generated declaration file .d.ts, cannot find name, symbol, TS2304

🕗 Version & Regression Information

Reproduces with TypeScript <=4.6 ~ 4.8.0-dev

Minimum repro: https://github.com/vilic/bug-repros/tree/typescript-generated-declaration-missing-import

🙁 Actual behavior

Emitted declaration file contains symbols not imported.

export declare const timestamp: {
    [timestampSymbol]: true;
//   ~~~~~~~~~~~~~~~ Cannot find name 'timestampSymbol'.
};

🙂 Expected behavior

Emits valid declaration file.

Might be related to the way I work around TS4023: instead of {[uniqueSymbol]: ...} I use {[TKey in typeof uniqueSymbol]: ...}.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Help Wanted You can do this Domain: Declaration Emit The issue relates to the emission of d.ts files Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". labels May 11, 2022
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.8.0 milestone May 11, 2022
@DanielRosenwasser DanielRosenwasser added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". and removed Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". labels May 11, 2022
@DanielRosenwasser
Copy link
Member

Might be related to the way I work around TS4023: instead of {[uniqueSymbol]: ...} I use {[TKey in typeof uniqueSymbol]: ...}.

Is there a reason for this? Are you using it in a union type?

@vilicvane
Copy link
Contributor Author

vilicvane commented May 11, 2022

@DanielRosenwasser You may try to change that part in the repro I provided into the {[uniqueSymbol]: ...} way, and it will result in TS4023. And I didn't find other ways to workaround that, including explicitly import * as x from or import {uniqueSymbol} from.

image

The real world case is here: https://github.com/vilic/x-value/blob/454824e43825628324a210586011d6cdb4ecbb36/src/library/type/refined-type.ts#L165

@vilicvane
Copy link
Contributor Author

It seems that using Record<typeof someSymbol, SomeType> can avoid this problem.

image

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 Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
4 participants