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
Defer distributing index over generic object types #50540
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15903,6 +15903,9 @@ namespace ts { | |
} | ||
|
||
function distributeIndexOverObjectType(objectType: Type, indexType: Type, writing: boolean) { | ||
if (shouldDeferIndexType(objectType)) { | ||
return; | ||
} | ||
// (T | U)[K] -> T[K] | U[K] (reading) | ||
// (T | U)[K] -> T[K] & U[K] (writing) | ||
// (T & U)[K] -> T[K] & U[K] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change the following line to: if (objectType.flags & TypeFlags.Union || objectType.Flags & TypeFlags.Intersection && !shouldDeferIndexType(objectType)) ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm concerned that |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
=== tests/cases/compiler/mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts === | ||
interface StateSchema { | ||
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0)) | ||
|
||
states?: { | ||
>states : Symbol(StateSchema.states, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 23)) | ||
|
||
[key: string]: StateSchema; | ||
>key : Symbol(key, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 2, 5)) | ||
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0)) | ||
|
||
}; | ||
} | ||
|
||
declare class StateNode<TStateSchema extends StateSchema> { | ||
>StateNode : Symbol(StateNode, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 4, 1)) | ||
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 6, 24)) | ||
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0)) | ||
|
||
schema: TStateSchema; | ||
>schema : Symbol(StateNode.schema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 6, 59)) | ||
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 6, 24)) | ||
} | ||
|
||
type StateNodesConfig<TStateSchema extends StateSchema> = { | ||
>StateNodesConfig : Symbol(StateNodesConfig, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 8, 1)) | ||
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 10, 22)) | ||
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0)) | ||
|
||
[K in keyof TStateSchema["states"]]: StateNode<NonNullable<TStateSchema["states"]>[K]>; | ||
>K : Symbol(K, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 11, 3)) | ||
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 10, 22)) | ||
>StateNode : Symbol(StateNode, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 4, 1)) | ||
>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) | ||
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 10, 22)) | ||
>K : Symbol(K, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 11, 3)) | ||
|
||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
=== tests/cases/compiler/mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts === | ||
interface StateSchema { | ||
states?: { | ||
>states : { [key: string]: StateSchema; } | undefined | ||
|
||
[key: string]: StateSchema; | ||
>key : string | ||
|
||
}; | ||
} | ||
|
||
declare class StateNode<TStateSchema extends StateSchema> { | ||
>StateNode : StateNode<TStateSchema> | ||
|
||
schema: TStateSchema; | ||
>schema : TStateSchema | ||
} | ||
|
||
type StateNodesConfig<TStateSchema extends StateSchema> = { | ||
>StateNodesConfig : StateNodesConfig<TStateSchema> | ||
|
||
[K in keyof TStateSchema["states"]]: StateNode<NonNullable<TStateSchema["states"]>[K]>; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @noEmit: true | ||
// @strict: true | ||
|
||
interface StateSchema { | ||
states?: { | ||
[key: string]: StateSchema; | ||
}; | ||
} | ||
|
||
declare class StateNode<TStateSchema extends StateSchema> { | ||
schema: TStateSchema; | ||
} | ||
|
||
type StateNodesConfig<TStateSchema extends StateSchema> = { | ||
[K in keyof TStateSchema["states"]]: StateNode<NonNullable<TStateSchema["states"]>[K]>; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this.