Bug Report
๐ Search Terms
Pick
๐ Version & Regression Information
v4.5.4
โฏ Playground Link
Link
๐ป Code
interface User {
name?: string
age?: number
address?: string
}
type Foo<T, U = keyof T> = {
[P in Extract<U, keyof T>]: T[P]
}
type Bar<T,U=keyof T> = Required<Pick<T, Extract<U, keyof T>>>
type Res = Foo<User, 'name'> //name: string | undefined;
type Res2 = Bar<User, 'name'> //name: string
// We can quickly address your report if:
// - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
// - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
// - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
// - We have to pare too much extraneous code.
// - We have to clone a large repo and validate that the problem isn't elsewhere.
// - The sample is confusing or doesn't clearly demonstrate what's wrong.
๐ Actual behavior
type Res = Foo<User, 'name'> //name: string | undefined;
The value evaluated for the name contains undefined
๐ Expected behavior
type Foo<T, U = keyof T> = {
[P in Extract<U, keyof T>]: T[P]
}
[P in Extract<U, keyof T>]: T[P] should not return undefined because Extract only narrows down the range of the keys
Bug Report
๐ Search Terms
Pick
๐ Version & Regression Information
v4.5.4
โฏ Playground Link
Link
๐ป Code
๐ Actual behavior
The value evaluated for the name contains undefined
๐ Expected behavior
[P in Extract<U, keyof T>]: T[P] should not return undefined because Extract only narrows down the range of the keys