Skip to content

Commit 9f806ef

Browse files
committed
Ensure type parameter lists are filled at each callsite, rather than within inference
1 parent 978b474 commit 9f806ef

7 files changed

+27
-31
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14896,11 +14896,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1489614896
const resolved = resolveAlias(aliasSymbol);
1489714897
if (resolved && resolved.flags & SymbolFlags.TypeAlias) {
1489814898
newAliasSymbol = resolved;
14899-
aliasTypeArguments = typeArgumentsFromTypeReferenceNode(node) || (typeParameters ? [] : undefined);
14899+
aliasTypeArguments = typeParameters ? fillMissingTypeArguments(typeArgumentsFromTypeReferenceNode(node), typeParameters, minTypeArgumentCount, isInJSFile(node)) : undefined;
1490014900
}
1490114901
}
1490214902
}
14903-
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), newAliasSymbol, aliasTypeArguments);
14903+
return getTypeAliasInstantiation(symbol, fillMissingTypeArguments(typeArgumentsFromTypeReferenceNode(node), typeParameters, minTypeArgumentCount, isInJSFile(node)), newAliasSymbol, aliasTypeArguments);
1490414904
}
1490514905
return checkNoTypeArguments(node, symbol) ? type : errorType;
1490614906
}
@@ -23698,12 +23698,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2369823698
if (source.aliasSymbol && source.aliasSymbol === target.aliasSymbol) {
2369923699
if (source.aliasTypeArguments) {
2370023700
// Source and target are types originating in the same generic type alias declaration.
23701-
// Simply infer from source type arguments to target type arguments, with defaults applied.
23702-
const params = getSymbolLinks(source.aliasSymbol).typeParameters!;
23703-
const minParams = getMinTypeArgumentCount(params);
23704-
const sourceTypes = fillMissingTypeArguments(source.aliasTypeArguments, params, minParams, /*isJs*/ false);
23705-
const targetTypes = fillMissingTypeArguments(target.aliasTypeArguments, params, minParams, /*isJs*/ false);
23706-
inferFromTypeArguments(sourceTypes, targetTypes!, getAliasVariances(source.aliasSymbol));
23701+
// Simply infer from source type arguments to target type arguments
23702+
inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments!, getAliasVariances(source.aliasSymbol));
2370723703
}
2370823704
// And if there weren't any type arguments, there's no reason to run inference as the types must be the same.
2370923705
return;

tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import { Component } from 'react';
8080
export declare function getComp(): Component;
8181
//// [inferred-comp-export.d.ts]
8282
export declare const obj: {
83-
comp: import("react").Component;
83+
comp: import("react").Component<any, {}, {}>;
8484
};
8585
//// [some-other-file.d.ts]
8686
export * from '@emotion/core';

tests/baselines/reference/declarationEmitExportAssignedNamespaceNoTripleSlashTypesReference.types

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ export function getComp(): Component {
3636
>getComp : () => Component
3737

3838
return {} as any as Component
39-
>{} as any as Component : Component
39+
>{} as any as Component : Component<any, {}, {}>
4040
>{} as any : any
4141
>{} : {}
4242
}
4343
=== tests/cases/compiler/src/inferred-comp-export.ts ===
4444
import { getComp } from "./get-comp";
45-
>getComp : () => import("tests/cases/compiler/node_modules/@types/react/index").Component
45+
>getComp : () => import("tests/cases/compiler/node_modules/@types/react/index").Component<any, {}, {}>
4646

4747
// this shouldn't need any triple-slash references - it should have a direct import to `react` and that's it
4848
// This issue (#35343) _only_ reproduces in the test harness when the file in question is in a subfolder
4949
export const obj = {
50-
>obj : { comp: import("tests/cases/compiler/node_modules/@types/react/index").Component; }
51-
>{ comp: getComp()} : { comp: import("tests/cases/compiler/node_modules/@types/react/index").Component; }
50+
>obj : { comp: import("tests/cases/compiler/node_modules/@types/react/index").Component<any, {}, {}>; }
51+
>{ comp: getComp()} : { comp: import("tests/cases/compiler/node_modules/@types/react/index").Component<any, {}, {}>; }
5252

5353
comp: getComp()
54-
>comp : import("tests/cases/compiler/node_modules/@types/react/index").Component
55-
>getComp() : import("tests/cases/compiler/node_modules/@types/react/index").Component
56-
>getComp : () => import("tests/cases/compiler/node_modules/@types/react/index").Component
54+
>comp : import("tests/cases/compiler/node_modules/@types/react/index").Component<any, {}, {}>
55+
>getComp() : import("tests/cases/compiler/node_modules/@types/react/index").Component<any, {}, {}>
56+
>getComp : () => import("tests/cases/compiler/node_modules/@types/react/index").Component<any, {}, {}>
5757
}
5858
=== tests/cases/compiler/src/some-other-file.ts ===
5959

tests/baselines/reference/fixCrashAliasLookupForDefauledImport.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import {Foo} from "./input";
88

99
function bar<T>(element: Foo) {
1010
>bar : <T>(element: Foo) => number
11-
>element : Foo
11+
>element : Foo<string>
1212

1313
return 1;
1414
>1 : 1
1515
}
1616

1717
bar(1 as Foo<number>);
1818
>bar(1 as Foo<number>) : number
19-
>bar : <T>(element: Foo) => number
19+
>bar : <T>(element: Foo<string>) => number
2020
>1 as Foo<number> : Foo<number>
2121
>1 : 1
2222

tests/baselines/reference/genericInferenceDefaultTypeParameterJsxReact.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type ButtonBaseProps<T extends ElementType> = ComponentPropsWithRef<T> & { child
1414
>children : React.ReactNode
1515

1616
function Component<T extends ElementType = 'span'>(props: ButtonBaseProps<T>) {
17-
>Component : <T extends React.ElementType = "span">(props: ButtonBaseProps<T>) => JSX.Element
17+
>Component : <T extends React.ElementType<any> = "span">(props: ButtonBaseProps<T>) => JSX.Element
1818
>props : ButtonBaseProps<T>
1919

2020
return <></>;
@@ -24,7 +24,7 @@ function Component<T extends ElementType = 'span'>(props: ButtonBaseProps<T>) {
2424
const v1 = <Component onClick={e => e.preventDefault()} />;
2525
>v1 : JSX.Element
2626
><Component onClick={e => e.preventDefault()} /> : JSX.Element
27-
>Component : <T extends React.ElementType = "span">(props: ButtonBaseProps<T>) => JSX.Element
27+
>Component : <T extends React.ElementType<any> = "span">(props: ButtonBaseProps<T>) => JSX.Element
2828
>onClick : (e: React.MouseEvent<HTMLSpanElement>) => void
2929
>e => e.preventDefault() : (e: React.MouseEvent<HTMLSpanElement>) => void
3030
>e : React.MouseEvent<HTMLSpanElement>

tests/baselines/reference/jsDeclarationsReactComponents.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ import React from "react";
6060
* @type {React.SFC}
6161
*/
6262
const TabbedShowLayout = () => {
63-
>TabbedShowLayout : React.SFC<{}>
64-
>() => { return ( <div className="" key=""> ok </div> );} : { (): JSX.Element; defaultProps: Partial<{}> | undefined; }
63+
>TabbedShowLayout : React.SFC<any>
64+
>() => { return ( <div className="" key=""> ok </div> );} : { (): JSX.Element; defaultProps: Partial<any> | undefined; }
6565

6666
return (
6767
>( <div className="" key=""> ok </div> ) : JSX.Element
@@ -81,9 +81,9 @@ const TabbedShowLayout = () => {
8181

8282
TabbedShowLayout.defaultProps = {
8383
>TabbedShowLayout.defaultProps = { tabs: "default value"} : { tabs: string; }
84-
>TabbedShowLayout.defaultProps : Partial<{}> | undefined
85-
>TabbedShowLayout : React.SFC<{}>
86-
>defaultProps : Partial<{}> | undefined
84+
>TabbedShowLayout.defaultProps : Partial<any> | undefined
85+
>TabbedShowLayout : React.SFC<any>
86+
>defaultProps : Partial<any> | undefined
8787
>{ tabs: "default value"} : { tabs: string; }
8888

8989
tabs: "default value"
@@ -93,7 +93,7 @@ TabbedShowLayout.defaultProps = {
9393
};
9494

9595
export default TabbedShowLayout;
96-
>TabbedShowLayout : React.SFC<{}>
96+
>TabbedShowLayout : React.SFC<any>
9797

9898
=== tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents3.jsx ===
9999
import React from "react";

tests/baselines/reference/ramdaToolsNoInfinite2.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ declare module "List/NonNullable" {
12111211
>NonNullable : NonNullable<L, K, depth>
12121212

12131213
1: Cast<ONonNullable<L, Key, depth>, List>;
1214-
>1 : Cast<ONonNullable<L, Key, depth>, List>
1214+
>1 : Cast<ONonNullable<L, Key, depth>, List<any>>
12151215

12161216
0: ListOf<ONonNullable<ObjectOf<L>, NumberOf<K>, depth>>;
12171217
>0 : ListOf<ONonNullable<ObjectOf<L>, NumberOf<K>, depth>>
@@ -1329,7 +1329,7 @@ declare module "Function/Curry" {
13291329
>0 : _GapsOf<L1, L2, GapOf<L1, L2, LN, I>, Next<I>>
13301330

13311331
1: _Concat<LN, _Drop<L2, Key<I>>>;
1332-
>1 : _Concat<LN, _Drop<L2, Key<I>>>
1332+
>1 : _Concat<LN, _Drop<L2, Key<I>, "->">>
13331333

13341334
}[Extends<Pos<I>, Length<L1>>];
13351335

@@ -1345,9 +1345,9 @@ declare module "Function/Curry" {
13451345
export type Curry<F extends Function> = <L extends List>(...args: Cast<L, Gaps<Parameters<F>>>) => GapsOf<L, Parameters<F>> extends infer G ? Length<Cast<G, List>> extends infer L ? L extends 0 ? Return<F> : L extends 1 ? Curry<(...args: Cast<G, List>) => Return<F>> & ((...args: Cast<G, List>) => Return<F>) : Curry<(...args: Cast<G, List>) => Return<F>> : never : never;
13461346
>Curry : Curry<F>
13471347
>args : Cast<L, Gaps<Parameters<F>>>
1348-
>args : Cast<G, List>
1349-
>args : Cast<G, List>
1350-
>args : Cast<G, List>
1348+
>args : Cast<G, List<any>>
1349+
>args : Cast<G, List<any>>
1350+
>args : Cast<G, List<any>>
13511351
}
13521352

13531353

0 commit comments

Comments
 (0)