microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Home Page:https://www.typescriptlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[transpileDeclaration API][5.5] Incorrectly creates new alias for generic parameter

MichaelMitchell-at opened this issue Β· comments

πŸ”Ž Search Terms

transpiledeclaration api alias generic parameter name

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?target=7&ts=5.5.0-dev.20240512#code/PTAEAEGcBcCcEsDG0Bco4FcCmAoEEATLRAGwENYzp4B7AOzU13ygAsaB3AUQFt5o8YNp179oWAgDF4JLGjIA6AguiRBESO259o4qTLmgARkpVr14AGYG6ZHocWqcWAB4AHGrGjoAnm6ygAErEngQAPADSWD6gruJ0BJCgMAh0AOYANKAAamQk2AB8oAC8oADeOKCgANoRoPB0oFE+ALpouflYANw4AL49FtaytvZoJk7wPB5e5UEhsASgvaCWsDQ8oABECsBkmz2u097QfgGSNDSRsS7xiclwDWlFpcGIoZFZdBg8RliwBQNDp5vG86DBQDQjAArErlSqgAg0AAqrEeVziWASSRSjwKAAoAPoAazQEQAlGhzpcIkUKlUqrAsNAMLBGmVlmQkmQ6D4elVehk+j0gA

πŸ’» Code

// @strict: true
// @declaration: true
// @showEmit
// @showEmittedFile: a.d.ts
// @showEmittedFile: b.d.ts

// @filename: a.ts
export type Record<Key extends string, Value> = {
  [K in Key]: Value;
};

// @filename: b.ts
import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;

export const obj = {
  doThing<K extends string>(_k: K): Foo<K> {
    return {} as any;
  },
};

πŸ™ Actual behavior

When using the API, b.d.ts is emitted as

import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;
export declare const obj: {
    doThing<K extends string>(_k: K): Record<K_1, number>;
};

while when using tsc it gets emitted as

import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;
export declare const obj: {
    doThing<K extends string>(_k: K): Foo<K>;
};

πŸ™‚ Expected behavior

Using the API should emit

import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;
export declare const obj: {
    doThing<K extends string>(_k: K): Foo<K>;
};

Additional information about the issue

No response