Skip to content

Syntax error in emitted declaration's generic arguments #42079

Open
@robpalme

Description

@robpalme

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;

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions