microsoft/TypeScript

Syntax error in emitted declaration's generic arguments

Opened this issue ยท 2 comments

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;

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.

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?