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

Syntax error in emitted declaration's generic arguments #42079

Open
robpalme opened this issue Dec 22, 2020 · 2 comments
Open

Syntax error in emitted declaration's generic arguments #42079

robpalme opened this issue Dec 22, 2020 · 2 comments
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 Rescheduled This issue was previously scheduled to an earlier milestone
Milestone

Comments

@robpalme
Copy link

Bug Report

🔎 Search Terms

syntax error declaration emit generics "Cannot find name" ts2304

🕗 Version & Regression Information

  • This is syntactically incorrect output from tsc
  • It is not a regression
  • This is the behavior in every version I tried (3.3 - 4.2.0-dev.20201222)

⏯ Playground Link

Playground link with relevant code

Important: The playground itself has a rendering bug in the display of the declaration. It still looks invalid. But it's invalid in another way in the truthful output. I paste the truthful output below.

💻 Code

// @declaration
type Wrap<A> = {
    nest: A
};
interface PreventInliningInDeclarationEmit {
}
export type PublicWrap<X, Y = {}> = Wrap<Y> & PreventInliningInDeclarationEmit;
export function fn<T> (arg: T) : PublicWrap<T> {
    return { nest: arg }
}
const nested = fn({ foo: 1});   // Syntax Error in declaration emit here
export default nested;

🙁 Actual behavior

Emitted declaration has syntax error. Cannot find name 'T'. (ts2304)

declare type Wrap<A> = {
    nest: A;
};
interface PreventInliningInDeclarationEmit {
}
export declare type PublicWrap<X, Y = {}> = Wrap<Y> & PreventInliningInDeclarationEmit;
export declare function fn<T>(arg: T): PublicWrap<T>;
declare const nested: PublicWrap<T, {}>;
export default nested;

🙂 Expected behavior

A valid declaration.

declare type Wrap<A> = {
    nest: A;
};
interface PreventInliningInDeclarationEmit {
}
export declare type PublicWrap<X, Y = {}> = Wrap<Y> & PreventInliningInDeclarationEmit;
export declare function fn<T>(arg: T): PublicWrap<T>;
declare const nested: PublicWrap<{
    foo: number;
}>;
export default nested;
@dragomirtitian
Copy link
Contributor

This does not to be just a declaration issue, tooltips also display T.

Calling getTypeOfSymbol for the nested variable symbol returns a type that still has the type parameter T in the type argument list, which it definitely should not be the case.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Dec 22, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.0 milestone Dec 22, 2020
@RyanCavanaugh RyanCavanaugh added the Domain: Declaration Emit The issue relates to the emission of d.ts files label Dec 22, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jan 4, 2021
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Mar 4, 2021
@RyanCavanaugh RyanCavanaugh removed this from the TypeScript 5.1.0 milestone Mar 4, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.5.0 milestone Mar 4, 2024
@MichaelMitchell-at
Copy link

Stumbled upon this issue when searching for existing issues related to #58807. Seems like this won't make into 5.5.0, so should probably update the milestone?

@weswigham weswigham modified the milestones: TypeScript 5.5.0, Backlog Jun 11, 2024
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 Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants