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

Open
vilic opened this issue May 11, 2022 · 3 comments
Open

Missing import in generated declaration file #49065

vilic opened this issue May 11, 2022 · 3 comments
Assignees
Labels
Bug Domain: Declaration Emit Effort: Moderate Help Wanted

Comments

@vilic
Copy link
Contributor

@vilic vilic commented May 11, 2022

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 Help Wanted Domain: Declaration Emit Effort: Casual labels May 11, 2022
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.8.0 milestone May 11, 2022
@DanielRosenwasser DanielRosenwasser added Effort: Moderate and removed Effort: Casual labels May 11, 2022
@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented May 11, 2022

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?

@vilic
Copy link
Contributor Author

@vilic vilic 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

@vilic
Copy link
Contributor Author

@vilic vilic commented May 17, 2022

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 Domain: Declaration Emit Effort: Moderate Help Wanted
Projects
None yet
Development

No branches or pull requests

3 participants