Skip to content
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

Fixed an issue with contextual type for intersection properties (take 2) #52095

Merged
Merged
Changes from 1 commit
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 Jan 2, 2023
5b9a5dd
Add failing test cases related to RTK
Andarist Jan 2, 2023
bafe4fb
Treat properties of non-generic mapped types as concrete-like
Andarist Jan 4, 2023
6bb681e
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Jan 17, 2023
59414ae
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Mar 22, 2023
19ab1c5
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist May 22, 2023
3ab5773
always concat indexed mapped type substitutions with either types fro…
Andarist May 22, 2023
48faaa3
tweak code
Andarist May 22, 2023
937a0ea
rename variable
Andarist May 22, 2023
5861cc0
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Jun 13, 2023
b9a9285
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Jul 25, 2023
6d24ca8
Add an extra test case related to JSX
Andarist Jul 25, 2023
ea31c96
expand the JSX test
Andarist Jul 25, 2023
f9744e8
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Dec 12, 2023
2fe75f1
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Mar 13, 2024
04bfab1
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Jul 30, 2024
1f9c4ea
add test case for intersected reverse mapped types
Andarist Jul 30, 2024
52effa5
add an extra test case
Andarist Jul 30, 2024
7211b09
specialcase negated-like conditional types
Andarist Jul 31, 2024
0b89c0f
add extra test case
Andarist Aug 1, 2024
7e90ef7
just intersect all of them but filter out anys
Andarist Aug 2, 2024
49bfb73
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Aug 2, 2024
01c20d4
go back to retrieving constituents separately
Andarist Aug 3, 2024
b0012cf
add an extra test case
Andarist Aug 3, 2024
a1c7ba1
add extra test cases
Andarist Aug 3, 2024
e3f9169
return `unknown` when no consistuent property types are found for int…
Andarist Aug 3, 2024
8645b94
small pr feedback
Andarist Aug 5, 2024
dac6f70
tighten up the check in `isExcludedMappedPropertyName`
Andarist Aug 6, 2024
adee09f
address PR feedback
Andarist Aug 6, 2024
e9502f9
fixed typo
Andarist Aug 7, 2024
f96d66e
Merge remote-tracking branch 'origin/main' into fix/contextual-inters…
Andarist Aug 19, 2024
c0e99ae
add extra test cases
Andarist Aug 19, 2024
f218b97
handle filtering mapped types as types that might exclude properties
Andarist Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
expand the JSX test
Andarist committed Jul 25, 2023
commit ea31c96a72f5c19b3d960b45dae3cdba83cbbb53
49 changes: 37 additions & 12 deletions tests/baselines/reference/contextuallyTypedJsxAttribute2.symbols
Original file line number Diff line number Diff line change
@@ -16,17 +16,42 @@ function UnwrappedLink<T extends ElementType = ElementType>(
>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31))
>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31))

props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as"> & {
props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as">,
>props : Symbol(props, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 60))
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --))
>ComponentPropsWithRef : Symbol(ComponentPropsWithRef, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 8))
>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31))
>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 23))
>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 23))

) {
return <a></a>;
>a : Symbol(JSX.IntrinsicElements.a, Decl(react16.d.ts, 2516, 41))
>a : Symbol(JSX.IntrinsicElements.a, Decl(react16.d.ts, 2516, 41))
}

<UnwrappedLink onClick={(e) => {}} />;
>UnwrappedLink : Symbol(UnwrappedLink, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 59))
>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 14))
>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 25))

function UnwrappedLink2<T extends ElementType = ElementType>(
>UnwrappedLink2 : Symbol(UnwrappedLink2, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 38))
>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24))
>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31))
>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31))

props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as"> & {
>props : Symbol(props, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 61))
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --))
>ComponentPropsWithRef : Symbol(ComponentPropsWithRef, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 8))
>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31))
>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24))
>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24))

as?: T;
>as : Symbol(as, Decl(contextuallyTypedJsxAttribute2.tsx, 6, 79))
>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 23))
>as : Symbol(as, Decl(contextuallyTypedJsxAttribute2.tsx, 14, 79))
>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24))

},
) {
@@ -35,14 +60,14 @@ function UnwrappedLink<T extends ElementType = ElementType>(
>a : Symbol(JSX.IntrinsicElements.a, Decl(react16.d.ts, 2516, 41))
}

<UnwrappedLink onClick={(e) => {}} />;
>UnwrappedLink : Symbol(UnwrappedLink, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 59))
>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 14))
>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 25))
<UnwrappedLink2 onClick={(e) => {}} />;
>UnwrappedLink2 : Symbol(UnwrappedLink2, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 38))
>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 21, 15))
>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 21, 26))

<UnwrappedLink as="button" onClick={(e) => {}} />;
>UnwrappedLink : Symbol(UnwrappedLink, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 59))
>as : Symbol(as, Decl(contextuallyTypedJsxAttribute2.tsx, 14, 14))
>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 14, 26))
>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 14, 37))
<UnwrappedLink2 as="button" onClick={(e) => {}} />;
>UnwrappedLink2 : Symbol(UnwrappedLink2, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 38))
>as : Symbol(as, Decl(contextuallyTypedJsxAttribute2.tsx, 22, 15))
>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 22, 27))
>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 22, 38))

34 changes: 27 additions & 7 deletions tests/baselines/reference/contextuallyTypedJsxAttribute2.types
Original file line number Diff line number Diff line change
@@ -11,7 +11,27 @@ import { ComponentPropsWithRef, ElementType } from "react";
>ElementType : any

function UnwrappedLink<T extends ElementType = ElementType>(
>UnwrappedLink : <T extends React.ElementType = React.ElementType>(props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as"> & { as?: T;}) => JSX.Element
>UnwrappedLink : <T extends React.ElementType = React.ElementType>(props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as">) => JSX.Element

props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as">,
>props : Omit<React.ComponentPropsWithRef<React.ElementType extends T ? "a" : T>, "as">

) {
return <a></a>;
><a></a> : JSX.Element
>a : any
>a : any
}

<UnwrappedLink onClick={(e) => {}} />;
><UnwrappedLink onClick={(e) => {}} /> : JSX.Element
>UnwrappedLink : <T extends React.ElementType = React.ElementType>(props: Omit<React.ComponentPropsWithRef<React.ElementType extends T ? "a" : T>, "as">) => JSX.Element
>onClick : (e: React.MouseEvent<HTMLAnchorElement>) => void
>(e) => {} : (e: React.MouseEvent<HTMLAnchorElement>) => void
>e : React.MouseEvent<HTMLAnchorElement>

function UnwrappedLink2<T extends ElementType = ElementType>(
>UnwrappedLink2 : <T extends React.ElementType = React.ElementType>(props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as"> & { as?: T;}) => JSX.Element

props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as"> & {
>props : Omit<React.ComponentPropsWithRef<React.ElementType extends T ? "a" : T>, "as"> & { as?: T | undefined; }
@@ -27,16 +47,16 @@ function UnwrappedLink<T extends ElementType = ElementType>(
>a : any
}

<UnwrappedLink onClick={(e) => {}} />;
><UnwrappedLink onClick={(e) => {}} /> : JSX.Element
>UnwrappedLink : <T extends React.ElementType = React.ElementType>(props: Omit<React.ComponentPropsWithRef<React.ElementType extends T ? "a" : T>, "as"> & { as?: T | undefined; }) => JSX.Element
<UnwrappedLink2 onClick={(e) => {}} />;
><UnwrappedLink2 onClick={(e) => {}} /> : JSX.Element
>UnwrappedLink2 : <T extends React.ElementType = React.ElementType>(props: Omit<React.ComponentPropsWithRef<React.ElementType extends T ? "a" : T>, "as"> & { as?: T | undefined; }) => JSX.Element
>onClick : (e: React.MouseEvent<HTMLAnchorElement>) => void
>(e) => {} : (e: React.MouseEvent<HTMLAnchorElement>) => void
>e : React.MouseEvent<HTMLAnchorElement>

<UnwrappedLink as="button" onClick={(e) => {}} />;
><UnwrappedLink as="button" onClick={(e) => {}} /> : JSX.Element
>UnwrappedLink : <T extends React.ElementType = React.ElementType>(props: Omit<React.ComponentPropsWithRef<React.ElementType extends T ? "a" : T>, "as"> & { as?: T | undefined; }) => JSX.Element
<UnwrappedLink2 as="button" onClick={(e) => {}} />;
><UnwrappedLink2 as="button" onClick={(e) => {}} /> : JSX.Element
>UnwrappedLink2 : <T extends React.ElementType = React.ElementType>(props: Omit<React.ComponentPropsWithRef<React.ElementType extends T ? "a" : T>, "as"> & { as?: T | undefined; }) => JSX.Element
>as : "button"
>onClick : (e: React.MouseEvent<HTMLButtonElement>) => void
>(e) => {} : (e: React.MouseEvent<HTMLButtonElement>) => void
12 changes: 10 additions & 2 deletions tests/cases/compiler/contextuallyTypedJsxAttribute2.tsx
Original file line number Diff line number Diff line change
@@ -9,12 +9,20 @@ import React from "react";
import { ComponentPropsWithRef, ElementType } from "react";

function UnwrappedLink<T extends ElementType = ElementType>(
props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as">,
) {
return <a></a>;
}

<UnwrappedLink onClick={(e) => {}} />;

function UnwrappedLink2<T extends ElementType = ElementType>(
props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as"> & {
as?: T;
},
) {
return <a></a>;
}

<UnwrappedLink onClick={(e) => {}} />;
<UnwrappedLink as="button" onClick={(e) => {}} />;
<UnwrappedLink2 onClick={(e) => {}} />;
<UnwrappedLink2 as="button" onClick={(e) => {}} />;