-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixed an issue with contextual type for intersection properties (take 2) #52095
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
Merged
gabritto
merged 33 commits into
microsoft:main
from
Andarist:fix/contextual-intersections-here-we-go-again
Aug 19, 2024
Merged
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f6074e8
Revert "Revert "Fixed an issue with contextual type for intersection …
Andarist 5b9a5dd
Add failing test cases related to RTK
Andarist bafe4fb
Treat properties of non-generic mapped types as concrete-like
Andarist 6bb681e
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 59414ae
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 19ab1c5
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 3ab5773
always concat indexed mapped type substitutions with either types fro…
Andarist 48faaa3
tweak code
Andarist 937a0ea
rename variable
Andarist 5861cc0
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist b9a9285
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 6d24ca8
Add an extra test case related to JSX
Andarist ea31c96
expand the JSX test
Andarist f9744e8
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 2fe75f1
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 04bfab1
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 1f9c4ea
add test case for intersected reverse mapped types
Andarist 52effa5
add an extra test case
Andarist 7211b09
specialcase negated-like conditional types
Andarist 0b89c0f
add extra test case
Andarist 7e90ef7
just intersect all of them but filter out anys
Andarist 49bfb73
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist 01c20d4
go back to retrieving constituents separately
Andarist b0012cf
add an extra test case
Andarist a1c7ba1
add extra test cases
Andarist e3f9169
return `unknown` when no consistuent property types are found for int…
Andarist 8645b94
small pr feedback
Andarist dac6f70
tighten up the check in `isExcludedMappedPropertyName`
Andarist adee09f
address PR feedback
Andarist e9502f9
fixed typo
Andarist f96d66e
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist c0e99ae
add extra test cases
Andarist f218b97
handle filtering mapped types as types that might exclude properties
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts] //// | ||
|
||
=== contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts === | ||
type ComponentType<P> = (p: P) => any; | ||
>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) | ||
>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 19)) | ||
>p : Symbol(p, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 25)) | ||
>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 19)) | ||
|
||
type ComponentProps<C> = C extends ComponentType<infer P> ? P : never; | ||
>ComponentProps : Symbol(ComponentProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 38)) | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 20)) | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 20)) | ||
>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) | ||
>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 54)) | ||
>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 54)) | ||
|
||
type Attrs<P, A extends Partial<P>> = A; | ||
>Attrs : Symbol(Attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 70)) | ||
>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 11)) | ||
>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 13)) | ||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) | ||
>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 11)) | ||
>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 13)) | ||
|
||
interface StyledFunction< | ||
>StyledFunction : Symbol(StyledFunction, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 40)) | ||
|
||
C extends ComponentType<any>, | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) | ||
>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) | ||
|
||
O extends object = {}, | ||
>O : Symbol(O, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 6, 31)) | ||
|
||
A extends keyof any = never, | ||
>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 7, 24)) | ||
|
||
> { | ||
attrs< | ||
>attrs : Symbol(StyledFunction.attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 9, 3)) | ||
|
||
U, | ||
>U : Symbol(U, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 10, 8)) | ||
|
||
NewA extends Partial<ComponentProps<C> & U> & { | ||
>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) | ||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) | ||
>ComponentProps : Symbol(ComponentProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 38)) | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) | ||
>U : Symbol(U, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 10, 8)) | ||
|
||
[others: string]: any; | ||
>others : Symbol(others, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 13, 7)) | ||
|
||
} = {}, | ||
>( | ||
attrs: Attrs<ComponentProps<C> & U, NewA>, | ||
>attrs : Symbol(attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 15, 4)) | ||
>Attrs : Symbol(Attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 70)) | ||
>ComponentProps : Symbol(ComponentProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 38)) | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) | ||
>U : Symbol(U, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 10, 8)) | ||
>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) | ||
|
||
): StyledFunction<C, O & NewA, A | keyof NewA>; | ||
>StyledFunction : Symbol(StyledFunction, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 40)) | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) | ||
>O : Symbol(O, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 6, 31)) | ||
>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) | ||
>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 7, 24)) | ||
>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) | ||
} | ||
|
||
interface StyledInterface { | ||
>StyledInterface : Symbol(StyledInterface, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 18, 1)) | ||
|
||
<C extends ComponentType<any>>(component: C): StyledFunction<C>; | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 3)) | ||
>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) | ||
>component : Symbol(component, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 33)) | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 3)) | ||
>StyledFunction : Symbol(StyledFunction, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 40)) | ||
>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 3)) | ||
} | ||
|
||
declare const styled: StyledInterface; | ||
>styled : Symbol(styled, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 13)) | ||
>StyledInterface : Symbol(StyledInterface, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 18, 1)) | ||
|
||
interface BaseProps { | ||
>BaseProps : Symbol(BaseProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 38)) | ||
|
||
as?: "select" | "input"; | ||
>as : Symbol(BaseProps.as, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 26, 21)) | ||
} | ||
|
||
declare const Flex: (props: BaseProps) => null; | ||
>Flex : Symbol(Flex, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 30, 13)) | ||
>props : Symbol(props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 30, 21)) | ||
>BaseProps : Symbol(BaseProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 38)) | ||
|
||
export const StyledSelect = styled(Flex).attrs({ | ||
>StyledSelect : Symbol(StyledSelect, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 32, 12)) | ||
>styled(Flex).attrs : Symbol(StyledFunction.attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 9, 3)) | ||
>styled : Symbol(styled, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 13)) | ||
>Flex : Symbol(Flex, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 30, 13)) | ||
>attrs : Symbol(StyledFunction.attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 9, 3)) | ||
|
||
as: "select", | ||
>as : Symbol(as, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 32, 48)) | ||
|
||
}); | ||
|
89 changes: 89 additions & 0 deletions
89
tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts] //// | ||
|
||
=== contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts === | ||
type ComponentType<P> = (p: P) => any; | ||
>ComponentType : ComponentType<P> | ||
> : ^^^^^^^^^^^^^^^^ | ||
>p : P | ||
> : ^ | ||
|
||
type ComponentProps<C> = C extends ComponentType<infer P> ? P : never; | ||
>ComponentProps : ComponentProps<C> | ||
> : ^^^^^^^^^^^^^^^^^ | ||
|
||
type Attrs<P, A extends Partial<P>> = A; | ||
>Attrs : A | ||
> : ^ | ||
|
||
interface StyledFunction< | ||
C extends ComponentType<any>, | ||
O extends object = {}, | ||
A extends keyof any = never, | ||
> { | ||
attrs< | ||
>attrs : <U, NewA extends Partial<ComponentProps<C> & U> & { [others: string]: any; } = {}>(attrs: Attrs<ComponentProps<C> & U, NewA>) => StyledFunction<C, O & NewA, A | keyof NewA> | ||
> : ^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ | ||
|
||
U, | ||
NewA extends Partial<ComponentProps<C> & U> & { | ||
[others: string]: any; | ||
>others : string | ||
> : ^^^^^^ | ||
|
||
} = {}, | ||
>( | ||
attrs: Attrs<ComponentProps<C> & U, NewA>, | ||
>attrs : NewA | ||
> : ^^^^ | ||
|
||
): StyledFunction<C, O & NewA, A | keyof NewA>; | ||
} | ||
|
||
interface StyledInterface { | ||
<C extends ComponentType<any>>(component: C): StyledFunction<C>; | ||
>component : C | ||
> : ^ | ||
} | ||
|
||
declare const styled: StyledInterface; | ||
>styled : StyledInterface | ||
> : ^^^^^^^^^^^^^^^ | ||
|
||
interface BaseProps { | ||
as?: "select" | "input"; | ||
>as : "select" | "input" | undefined | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
} | ||
|
||
declare const Flex: (props: BaseProps) => null; | ||
>Flex : (props: BaseProps) => null | ||
> : ^ ^^ ^^^^^ | ||
>props : BaseProps | ||
> : ^^^^^^^^^ | ||
|
||
export const StyledSelect = styled(Flex).attrs({ | ||
>StyledSelect : StyledFunction<(props: BaseProps) => null, { as: "select"; }, "as"> | ||
> : ^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>styled(Flex).attrs({ as: "select",}) : StyledFunction<(props: BaseProps) => null, { as: "select"; }, "as"> | ||
> : ^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>styled(Flex).attrs : <U, NewA extends Partial<BaseProps & U> & { [others: string]: any; } = {}>(attrs: NewA) => StyledFunction<(props: BaseProps) => null, {} & NewA, keyof NewA> | ||
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>styled(Flex) : StyledFunction<(props: BaseProps) => null, {}, never> | ||
> : ^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^ | ||
>styled : StyledInterface | ||
> : ^^^^^^^^^^^^^^^ | ||
>Flex : (props: BaseProps) => null | ||
> : ^ ^^ ^^^^^ | ||
>attrs : <U, NewA extends Partial<BaseProps & U> & { [others: string]: any; } = {}>(attrs: NewA) => StyledFunction<(props: BaseProps) => null, {} & NewA, keyof NewA> | ||
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>{ as: "select",} : { as: "select"; } | ||
> : ^^^^^^^^^^^^^^^^^ | ||
|
||
as: "select", | ||
>as : "select" | ||
> : ^^^^^^^^ | ||
>"select" : "select" | ||
> : ^^^^^^^^ | ||
|
||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.