-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Domain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts filesFix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
π Search Terms
mapped type, narrow, optional, undefined, union
π Version & Regression Information
This changed between versions 5.4 and 5.5. This can be reproduced in the playground.
β― Playground Link
π» Code
type InexactOptionals<A> = {
[K in keyof A as undefined extends A[K] ? K : never]?: undefined extends A[K]
? A[K] | undefined
: A[K];
} & {
[K in keyof A as undefined extends A[K] ? never : K]: A[K];
};
type In = {
foo?: string;
bar: number;
baz: undefined;
}
// Expected: { foo?: string | undefined; bar: number; baz?: undefined; }
type Out = InexactOptionals<In>
π Actual behavior
The A[K] | undefined
in the mapped type ternary is narrowed to A[K]
, meaning that foo
in the example is foo?: string
.
π Expected behavior
The A[K] | undefined
in the mapped type ternary is not narrowed, so we see foo?: string | undefined
as expected.
Additional information about the issue
My use case is cheaply migrating a codebase to support exactOptionalPropertyTypes
. It can also be useful for better React DX.
Metadata
Metadata
Assignees
Labels
Domain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts filesFix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.