Skip to content

Mapped type in generic function can cause unbound generic to leakΒ #43277

Description

@tjjfvi

Bug Report

πŸ”Ž Search Terms

unbound type parameter generic leak

πŸ•— Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Workbench Repro

πŸ’» Code

// @declaration

export const obj = <A,>(shape: { [K in keyof A]: A[K] }) => shape

// .d.ts shows correct type
export const box = <B,>(t: B) => obj({ value: t });
//           ^?
// Type looks correct

// .d.ts shows const x: { value: B }
export const x = box(5)
//               ^?
// Shows unbound B

// .d.ts shows const x: { value: B }
export const y = x
//           ^?
// Shows unbound B

// .d.ts shows type U = typeof x.value
export type U = typeof x.value
//          ^?
// Shows unbound B

πŸ™ Actual behavior

The type of x is { value: B }, where B is an unbound generic that leaked from box

πŸ™‚ Expected behavior

The type of x is { value: number }

Related Issues

#31326, #31402

/cc Sam Holmes (@samholmes)

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions