Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@tjjfvi

Description

@tjjfvi
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.