Skip to content

5.4 omits certain import * as ... statements from .d.ts #57861

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
ammut opened this issue Mar 20, 2024 · 4 comments Β· Fixed by #57887
Closed

5.4 omits certain import * as ... statements from .d.ts #57861

ammut opened this issue Mar 20, 2024 · 4 comments Β· Fixed by #57887
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@ammut
Copy link

ammut commented Mar 20, 2024

πŸ”Ž Search Terms

omit, emit, 5.4, import, import *

πŸ•— Version & Regression Information

  • This emits incorrect .d.ts
  • This changed between versions 5.3 and 5.4
  • This still breaks in typescript@next

⏯ Playground Link

https://www.typescriptlang.org/play?target=99&moduleResolution=99&module=199&ts=5.4.2&useDefineForClassFields=true&noUnusedLocals=true&noUnusedParameters=true&preserveConstEnums=true&importHelpers=true&experimentalDecorators=true&emitDecoratorMetadata=true&jsx=0&isolatedModules=true&verbatimModuleSyntax=true&pretty=true&noErrorTruncation=true&noFallthroughCasesInSwitch=true&noImplicitOverride=true&noPropertyAccessFromIndexSignature=true&useUnknownInCatchVariables=true#code/JYWwDg9gTgLgBAKjgQwM5wIJjgMyhEOAchzAFoZUB6LMAGwE8iBuAKFElkRXQFFd8hEuUpVewGAAsAplBbtw0eEjRwAkgHkBBYqQrVN8jku6rN07UL2jN4qbKOKuMBmAsr0miJd0iDGjTAYYAgAO0dOeABvOABjMNQYADFkOlRpABo4hJgAFSgAV0zcOggAdyywYDc4AF8fYX0qHALQ2OCwiJMXGpiAGWQALwY6hutqFraO8LZWaQAPSO48HUabDTsZOVmFpfjQxMsAOQK6OmQAIzppAC44AB5eAD4AClu4AeHHp4BKOABeJ4PDCvc53DB-QHqDTSAB0tgkW0eWSOYROZ0u13uIKB-1YcDgb0hQJe52JhOJ+IJcF4sJWIHR5yu0jeLx+P1JyB+O0WJn2h3pmkC0zu3xeVLRYXenwY3wyrHJ2NeOGQdy88ICQRCoSV5PMGs2smRmFxhMloWkeo0sJAyDAL1p9OF2pe5st3NYc15XH58EKoQBD14WRBL2AaphBsRRuDJp+d1phqgxpBAKBwDZPL2OTg-oAqqFtaLYxgsgAhV5UnB3N4J8ll+UEgDmNdVmHr8vJLxVEbhCPsyZLvzTcDLge7WSb5JwpTKL31F1AdoncCnWX1MAgBe1WReMHJMDZHq92YO8HSAEcim1pABlQNYWGX6+xO-zyO0OjAWLIYIAN2kAAFZAoGPXY+RzJtpBgDQoFySR8DKAEqTFTd4MQzF3lrGlyV4KB8FAtMUNDHtoT7DZo0HENfnBIjqTgKo3HFeiCX9bsuUbFjaSgmCoF4NJpBTV4iRHKIqRYuApEQySIHQ8pMKJNgJNqH5OIJMDvXgX04AWYBElQYtqO7VtwXJC4IAga5kFCLtSP1fskSHMyLKsgN-kJHBKVY1ptzCF5fRSASsk8rMILPOA9L6aQcBgQyTXY3sowHITnMs6RrMDfNCz8318iKLIAtSdINNPQ49IAJWAJtJFioMjLsyMHJjajUtczKfOy0J-JyQL0gKnI8stUKfRzGA7SimK4tDKsa3eXhyT-CBgAAE07EcErIpLHJakd7Io5Kh3HTy6M220wAmw8XnmckxPonAro9eioGggooADeYlLqD0gA

πŸ’» Code

// io-either.ts
import * as E from 'fp-ts/Either';
import * as IOe from 'fp-ts/IOEither';

export declare const run: <E, A>(i: IOe.IOEither<E, A>) => E.Either<E, A>;

πŸ™ Actual behavior

// io-either.d.ts
import * as IOe from 'fp-ts/IOEither';

export declare const run: <E, A>(i: IOe.IOEither<E, A>) => E.Either<E, A>;

The import * as E from 'fp-ts/Either' statement is missing in the .d.ts, leading to run having a return type of effectively any.

πŸ™‚ Expected behavior

// io-either.d.ts
import * as E from 'fp-ts/Either';
import * as IOe from 'fp-ts/IOEither';

export declare const run: <E, A>(i: IOe.IOEither<E, A>) => E.Either<E, A>;

The import * as E ... statement should be in the emitted .d.ts, otherwise E.Either<E, A> cannot possibly be resolved.

Additional information about the issue

Locally I was able to produce a working .d.ts using 5.3.3, but not using 5.4.2. Unfortunately I wasn't able to produce a correct .d.ts in the playground, but at least there the output is consistently incorrect.

I am aware that in the scope of => E.Either<E, A> there are two symbols called E, one referring to the type parameter, the other referring to the module import. when importing and using this .ts directly, everything works as expected, so TS seems to be able to differentiate between these two just fine.

However, I was able to workaround this issue by renaming either of the two symbols, so they don't "clash".

@jakebailey
Copy link
Member

This isn't a super minimal repro; can you try https://www.npmjs.com/package/every-ts to bisect this down between the two releases?

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 20, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.5.0 milestone Mar 20, 2024
@ammut
Copy link
Author

ammut commented Mar 21, 2024

I tried it, but every-ts kept crashing on my machine. Will try again.

@ammut
Copy link
Author

ammut commented Mar 21, 2024

every-ts found:

1ed8ed6c2704f0d7e1af05273226119bc5b83705 is the first bad commit
commit 1ed8ed6c2704f0d7e1af05273226119bc5b83705
Author: Jake Bailey <[email protected]>
Date:   Mon Nov 6 15:45:16 2023 -0800

    Preserve original type parameter names more often when shadowed (#55820)
    
    Co-authored-by: Wesley Wigham <[email protected]>

@ammut
Copy link
Author

ammut commented Mar 21, 2024

I made a smaller example here.

the '.D.TS' output is clearly missing an import statement - that's the gist of the Bug I'm reporting here. The missing import statement immediately appears, when either E is renamed.

However, I'm not able to create a Playground project where the '.D.TS' output is correct despite the name conflict. I've only been able to achieve that when working locally, using TS v5.3.3 (or any commit before the abovementioned First Bad Commit, really).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
6 participants