Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tjjfvi opened this issue Mar 16, 2021 · 1 comment
Closed

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

tjjfvi opened this issue Mar 16, 2021 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@tjjfvi
Copy link
Contributor

tjjfvi commented Mar 16, 2021

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 @samholmes

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 16, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.1 milestone Mar 16, 2021
@andrewbranch andrewbranch added the Fix Available A PR has been opened for this issue label Apr 26, 2021
@andrewbranch
Copy link
Member

Fixed by #42449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

No branches or pull requests

3 participants