Skip to content

Commit

Permalink
Merge pull request microsoft#30963 from Microsoft/fixObjectFlagsPropa…
Browse files Browse the repository at this point in the history
…gation

Fix object flags propagation
  • Loading branch information
ahejlsberg authored and RyanCavanaugh committed Apr 16, 2019
1 parent 8ba211c commit 519d0e6
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Expand Up @@ -14133,7 +14133,7 @@ namespace ts {
const result = createAnonymousType(type.symbol, members, emptyArray, emptyArray,
stringIndexInfo && createIndexInfo(getWidenedType(stringIndexInfo.type), stringIndexInfo.isReadonly),
numberIndexInfo && createIndexInfo(getWidenedType(numberIndexInfo.type), numberIndexInfo.isReadonly));
result.objectFlags |= (getObjectFlags(type) & ObjectFlags.JSLiteral); // Retain js literal flag through widening
result.objectFlags |= (getObjectFlags(type) & (ObjectFlags.JSLiteral | ObjectFlags.NonInferrableType)); // Retain js literal flag through widening
return result;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/genericFunctionInference2.js
Expand Up @@ -14,6 +14,21 @@ const myReducer1: Reducer<MyState> = combineReducers({
const myReducer2 = combineReducers({
combined: combineReducers({ foo }),
});

// Repro from #30942

declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;

type Props = { out: number }

type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };

const enhancer4 = withH((props: Props) => ({
onChange: (props) => (e: any) => {},
onSubmit: (props) => (e: any) => {},
}));

enhancer4.onChange(null);


//// [genericFunctionInference2.js]
Expand All @@ -24,3 +39,8 @@ var myReducer1 = combineReducers({
var myReducer2 = combineReducers({
combined: combineReducers({ foo: foo })
});
var enhancer4 = withH(function (props) { return ({
onChange: function (props) { return function (e) { }; },
onSubmit: function (props) { return function (e) { }; }
}); });
enhancer4.onChange(null);
52 changes: 52 additions & 0 deletions tests/baselines/reference/genericFunctionInference2.symbols
Expand Up @@ -54,3 +54,55 @@ const myReducer2 = combineReducers({

});

// Repro from #30942

declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;
>withH : Symbol(withH, Decl(genericFunctionInference2.ts, 14, 3))
>T : Symbol(T, Decl(genericFunctionInference2.ts, 18, 23))
>U : Symbol(U, Decl(genericFunctionInference2.ts, 18, 25))
>handlerCreators : Symbol(handlerCreators, Decl(genericFunctionInference2.ts, 18, 29))
>HandleCreatorsFactory : Symbol(HandleCreatorsFactory, Decl(genericFunctionInference2.ts, 20, 28))
>T : Symbol(T, Decl(genericFunctionInference2.ts, 18, 23))
>U : Symbol(U, Decl(genericFunctionInference2.ts, 18, 25))
>U : Symbol(U, Decl(genericFunctionInference2.ts, 18, 25))

type Props = { out: number }
>Props : Symbol(Props, Decl(genericFunctionInference2.ts, 18, 78))
>out : Symbol(out, Decl(genericFunctionInference2.ts, 20, 14))

type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };
>HandleCreatorsFactory : Symbol(HandleCreatorsFactory, Decl(genericFunctionInference2.ts, 20, 28))
>T : Symbol(T, Decl(genericFunctionInference2.ts, 22, 27))
>U : Symbol(U, Decl(genericFunctionInference2.ts, 22, 29))
>initialProps : Symbol(initialProps, Decl(genericFunctionInference2.ts, 22, 36))
>T : Symbol(T, Decl(genericFunctionInference2.ts, 22, 27))
>P : Symbol(P, Decl(genericFunctionInference2.ts, 22, 59))
>U : Symbol(U, Decl(genericFunctionInference2.ts, 22, 29))
>props : Symbol(props, Decl(genericFunctionInference2.ts, 22, 75))
>T : Symbol(T, Decl(genericFunctionInference2.ts, 22, 27))
>U : Symbol(U, Decl(genericFunctionInference2.ts, 22, 29))
>P : Symbol(P, Decl(genericFunctionInference2.ts, 22, 59))

const enhancer4 = withH((props: Props) => ({
>enhancer4 : Symbol(enhancer4, Decl(genericFunctionInference2.ts, 24, 5))
>withH : Symbol(withH, Decl(genericFunctionInference2.ts, 14, 3))
>props : Symbol(props, Decl(genericFunctionInference2.ts, 24, 25))
>Props : Symbol(Props, Decl(genericFunctionInference2.ts, 18, 78))

onChange: (props) => (e: any) => {},
>onChange : Symbol(onChange, Decl(genericFunctionInference2.ts, 24, 44))
>props : Symbol(props, Decl(genericFunctionInference2.ts, 25, 15))
>e : Symbol(e, Decl(genericFunctionInference2.ts, 25, 26))

onSubmit: (props) => (e: any) => {},
>onSubmit : Symbol(onSubmit, Decl(genericFunctionInference2.ts, 25, 40))
>props : Symbol(props, Decl(genericFunctionInference2.ts, 26, 15))
>e : Symbol(e, Decl(genericFunctionInference2.ts, 26, 26))

}));

enhancer4.onChange(null);
>enhancer4.onChange : Symbol(onChange, Decl(genericFunctionInference2.ts, 24, 44))
>enhancer4 : Symbol(enhancer4, Decl(genericFunctionInference2.ts, 24, 5))
>onChange : Symbol(onChange, Decl(genericFunctionInference2.ts, 24, 44))

47 changes: 47 additions & 0 deletions tests/baselines/reference/genericFunctionInference2.types
Expand Up @@ -47,3 +47,50 @@ const myReducer2 = combineReducers({

});

// Repro from #30942

declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;
>withH : <T, U>(handlerCreators: HandleCreatorsFactory<T, U>) => U
>handlerCreators : HandleCreatorsFactory<T, U>

type Props = { out: number }
>Props : Props
>out : number

type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };
>HandleCreatorsFactory : HandleCreatorsFactory<T, U>
>initialProps : T
>props : T

const enhancer4 = withH((props: Props) => ({
>enhancer4 : { onChange: (e: any) => void; onSubmit: (e: any) => void; }
>withH((props: Props) => ({ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},})) : { onChange: (e: any) => void; onSubmit: (e: any) => void; }
>withH : <T, U>(handlerCreators: HandleCreatorsFactory<T, U>) => U
>(props: Props) => ({ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},}) : (props: Props) => { onChange: (props: Props) => (e: any) => void; onSubmit: (props: Props) => (e: any) => void; }
>props : Props
>({ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},}) : { onChange: (props: Props) => (e: any) => void; onSubmit: (props: Props) => (e: any) => void; }
>{ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},} : { onChange: (props: Props) => (e: any) => void; onSubmit: (props: Props) => (e: any) => void; }

onChange: (props) => (e: any) => {},
>onChange : (props: Props) => (e: any) => void
>(props) => (e: any) => {} : (props: Props) => (e: any) => void
>props : Props
>(e: any) => {} : (e: any) => void
>e : any

onSubmit: (props) => (e: any) => {},
>onSubmit : (props: Props) => (e: any) => void
>(props) => (e: any) => {} : (props: Props) => (e: any) => void
>props : Props
>(e: any) => {} : (e: any) => void
>e : any

}));

enhancer4.onChange(null);
>enhancer4.onChange(null) : void
>enhancer4.onChange : (e: any) => void
>enhancer4 : { onChange: (e: any) => void; onSubmit: (e: any) => void; }
>onChange : (e: any) => void
>null : null

15 changes: 15 additions & 0 deletions tests/cases/compiler/genericFunctionInference2.ts
Expand Up @@ -13,3 +13,18 @@ const myReducer1: Reducer<MyState> = combineReducers({
const myReducer2 = combineReducers({
combined: combineReducers({ foo }),
});

// Repro from #30942

declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;

type Props = { out: number }

type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };

const enhancer4 = withH((props: Props) => ({
onChange: (props) => (e: any) => {},
onSubmit: (props) => (e: any) => {},
}));

enhancer4.onChange(null);

0 comments on commit 519d0e6

Please sign in to comment.