Skip to content

Commit 0dbad04

Browse files
authored
Distribute indexed accesses when simplifying them (#26281)
* unknownify accesses * Move to simplify to break less with fewer changes * Accept baselines for now * Always propegate any as an index type * Fix flow control in the presence of simplifiable types * Add spy repro from #25181 * Retain errorType when it is used as a marker for the lack of a constraint * Small refinement * Add new test * Move most potentially recursive types from isIdenticalTo into structuredTypeRelatedTo to match the non-identity relations * Fix nits * Doesnt need to be undefineable at all
1 parent 0a59da1 commit 0dbad04

File tree

62 files changed

+1462
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1462
-244
lines changed

src/compiler/checker.ts

+65-92
Large diffs are not rendered by default.

tests/baselines/reference/assignmentCompatForEnums.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function foo() {
2323

2424
var x: TokenType = list['one'];
2525
>x : TokenType
26-
>list['one'] : any
26+
>list['one'] : error
2727
>list : {}
2828
>'one' : "one"
2929
}

tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ interface Function {
1616
}
1717

1818
var a = {}[0]; // Should be Foo
19-
>a : any
20-
>{}[0] : any
19+
>a : error
20+
>{}[0] : error
2121
>{} : {}
2222
>0 : 0
2323

2424
var b = (() => { })[0]; // Should be Bar
25-
>b : any
26-
>(() => { })[0] : any
25+
>b : error
26+
>(() => { })[0] : error
2727
>(() => { }) : () => void
2828
>() => { } : () => void
2929
>0 : 0

tests/baselines/reference/augmentedTypeBracketNamedPropertyAccess.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ var r1 = o['data']; // Should be number
2222
>'data' : "data"
2323

2424
var r2 = o['functionData']; // Should be any (no property found)
25-
>r2 : any
26-
>o['functionData'] : any
25+
>r2 : error
26+
>o['functionData'] : error
2727
>o : {}
2828
>'functionData' : "functionData"
2929

tests/baselines/reference/binaryIntegerLiteral.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ obj1["26"]; // string
7979
>"26" : "26"
8080

8181
obj1["0b11010"]; // any
82-
>obj1["0b11010"] : any
82+
>obj1["0b11010"] : error
8383
>obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
8484
>"0b11010" : "0b11010"
8585

@@ -119,7 +119,7 @@ obj2["26"]; // string
119119
>"26" : "26"
120120

121121
obj2["0B11010"]; // any
122-
>obj2["0B11010"] : any
122+
>obj2["0B11010"] : error
123123
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
124124
>"0B11010" : "0B11010"
125125

@@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean
149149
>"9.671406556917009e+24" : "9.671406556917009e+24"
150150

151151
obj2["Infinity"]; // any
152-
>obj2["Infinity"] : any
152+
>obj2["Infinity"] : error
153153
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
154154
>"Infinity" : "Infinity"
155155

tests/baselines/reference/binaryIntegerLiteralES6.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ obj1["26"]; // string
7979
>"26" : "26"
8080

8181
obj1["0b11010"]; // any
82-
>obj1["0b11010"] : any
82+
>obj1["0b11010"] : error
8383
>obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
8484
>"0b11010" : "0b11010"
8585

@@ -119,7 +119,7 @@ obj2["26"]; // string
119119
>"26" : "26"
120120

121121
obj2["0B11010"]; // any
122-
>obj2["0B11010"] : any
122+
>obj2["0B11010"] : error
123123
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
124124
>"0B11010" : "0B11010"
125125

@@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean
149149
>"9.671406556917009e+24" : "9.671406556917009e+24"
150150

151151
obj2["Infinity"]; // any
152-
>obj2["Infinity"] : any
152+
>obj2["Infinity"] : error
153153
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
154154
>"Infinity" : "Infinity"
155155

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [circularlySimplifyingConditionalTypesNoCrash.ts]
2+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
3+
4+
type Shared< // Circularly self constraining type, defered thanks to mapping
5+
InjectedProps,
6+
DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps>
7+
> = {
8+
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
9+
};
10+
11+
interface ComponentClass<P> {
12+
defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional
13+
}
14+
15+
interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
16+
<P extends Shared<TInjectedProps, P>>(
17+
component: ComponentClass<P>
18+
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> }
19+
} // Then intersected with and indexed via Omit and &
20+
21+
interface Connect { // Then strictly compared with another signature in its context
22+
<TStateProps, TOwnProps>(
23+
mapStateToProps: unknown,
24+
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>;
25+
26+
<TDispatchProps, TOwnProps>(
27+
mapStateToProps: null | undefined,
28+
mapDispatchToProps: unknown,
29+
mergeProps: null | undefined,
30+
options: unknown
31+
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
32+
}
33+
34+
declare var connect: Connect;
35+
36+
const myStoreConnect: Connect = function(
37+
mapStateToProps?: any,
38+
mapDispatchToProps?: any,
39+
mergeProps?: any,
40+
options: unknown = {},
41+
) {
42+
return connect(
43+
mapStateToProps,
44+
mapDispatchToProps,
45+
mergeProps,
46+
options,
47+
);
48+
};
49+
50+
//// [circularlySimplifyingConditionalTypesNoCrash.js]
51+
"use strict";
52+
var myStoreConnect = function (mapStateToProps, mapDispatchToProps, mergeProps, options) {
53+
if (options === void 0) { options = {}; }
54+
return connect(mapStateToProps, mapDispatchToProps, mergeProps, options);
55+
};

0 commit comments

Comments
 (0)