Skip to content

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

Closed
@MichaelMitchell-at

Description

@MichaelMitchell-at

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesDomain: ts.transpileDeclarationIssues regarding the transpileDeclaration API, which do not reproduce without it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions