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

Distribute indexed accesses when simplifying them #26281

Merged
merged 14 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
157 changes: 65 additions & 92 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/baselines/reference/assignmentCompatForEnums.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function foo() {

var x: TokenType = list['one'];
>x : TokenType
>list['one'] : any
>list['one'] : error
>list : {}
>'one' : "one"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ interface Function {
}

var a = {}[0]; // Should be Foo
>a : any
>{}[0] : any
>a : error
>{}[0] : error
>{} : {}
>0 : 0

var b = (() => { })[0]; // Should be Bar
>b : any
>(() => { })[0] : any
>b : error
>(() => { })[0] : error
>(() => { }) : () => void
>() => { } : () => void
>0 : 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var r1 = o['data']; // Should be number
>'data' : "data"

var r2 = o['functionData']; // Should be any (no property found)
>r2 : any
>o['functionData'] : any
>r2 : error
>o['functionData'] : error
>o : {}
>'functionData' : "functionData"

Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/binaryIntegerLiteral.types
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ obj1["26"]; // string
>"26" : "26"

obj1["0b11010"]; // any
>obj1["0b11010"] : any
>obj1["0b11010"] : error
>obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
>"0b11010" : "0b11010"

Expand Down Expand Up @@ -119,7 +119,7 @@ obj2["26"]; // string
>"26" : "26"

obj2["0B11010"]; // any
>obj2["0B11010"] : any
>obj2["0B11010"] : error
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
>"0B11010" : "0B11010"

Expand Down Expand Up @@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean
>"9.671406556917009e+24" : "9.671406556917009e+24"

obj2["Infinity"]; // any
>obj2["Infinity"] : any
>obj2["Infinity"] : error
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
>"Infinity" : "Infinity"

Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/binaryIntegerLiteralES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ obj1["26"]; // string
>"26" : "26"

obj1["0b11010"]; // any
>obj1["0b11010"] : any
>obj1["0b11010"] : error
>obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
>"0b11010" : "0b11010"

Expand Down Expand Up @@ -119,7 +119,7 @@ obj2["26"]; // string
>"26" : "26"

obj2["0B11010"]; // any
>obj2["0B11010"] : any
>obj2["0B11010"] : error
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
>"0B11010" : "0B11010"

Expand Down Expand Up @@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean
>"9.671406556917009e+24" : "9.671406556917009e+24"

obj2["Infinity"]; // any
>obj2["Infinity"] : any
>obj2["Infinity"] : error
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
>"Infinity" : "Infinity"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//// [circularlySimplifyingConditionalTypesNoCrash.ts]
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

type Shared< // Circularly self constraining type, defered thanks to mapping
InjectedProps,
DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps>
> = {
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
};

interface ComponentClass<P> {
defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional
}

interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
<P extends Shared<TInjectedProps, P>>(
component: ComponentClass<P>
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> }
} // Then intersected with and indexed via Omit and &

interface Connect { // Then strictly compared with another signature in its context
<TStateProps, TOwnProps>(
mapStateToProps: unknown,
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>;

<TDispatchProps, TOwnProps>(
mapStateToProps: null | undefined,
mapDispatchToProps: unknown,
mergeProps: null | undefined,
options: unknown
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
}

declare var connect: Connect;

const myStoreConnect: Connect = function(
mapStateToProps?: any,
mapDispatchToProps?: any,
mergeProps?: any,
options: unknown = {},
) {
return connect(
mapStateToProps,
mapDispatchToProps,
mergeProps,
options,
);
};

//// [circularlySimplifyingConditionalTypesNoCrash.js]
"use strict";
var myStoreConnect = function (mapStateToProps, mapDispatchToProps, mergeProps, options) {
if (options === void 0) { options = {}; }
return connect(mapStateToProps, mapDispatchToProps, mergeProps, options);
};
Loading