Skip to content

Commit f617d16

Browse files
authored
Merge pull request #30963 from Microsoft/fixObjectFlagsPropagation
Fix object flags propagation
2 parents ec70c80 + 4668411 commit f617d16

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14271,7 +14271,7 @@ namespace ts {
1427114271
const result = createAnonymousType(type.symbol, members, emptyArray, emptyArray,
1427214272
stringIndexInfo && createIndexInfo(getWidenedType(stringIndexInfo.type), stringIndexInfo.isReadonly),
1427314273
numberIndexInfo && createIndexInfo(getWidenedType(numberIndexInfo.type), numberIndexInfo.isReadonly));
14274-
result.objectFlags |= (getObjectFlags(type) & ObjectFlags.JSLiteral); // Retain js literal flag through widening
14274+
result.objectFlags |= (getObjectFlags(type) & (ObjectFlags.JSLiteral | ObjectFlags.NonInferrableType)); // Retain js literal flag through widening
1427514275
return result;
1427614276
}
1427714277

tests/baselines/reference/genericFunctionInference2.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ const myReducer1: Reducer<MyState> = combineReducers({
1414
const myReducer2 = combineReducers({
1515
combined: combineReducers({ foo }),
1616
});
17+
18+
// Repro from #30942
19+
20+
declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;
21+
22+
type Props = { out: number }
23+
24+
type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };
25+
26+
const enhancer4 = withH((props: Props) => ({
27+
onChange: (props) => (e: any) => {},
28+
onSubmit: (props) => (e: any) => {},
29+
}));
30+
31+
enhancer4.onChange(null);
1732

1833

1934
//// [genericFunctionInference2.js]
@@ -24,3 +39,8 @@ var myReducer1 = combineReducers({
2439
var myReducer2 = combineReducers({
2540
combined: combineReducers({ foo: foo })
2641
});
42+
var enhancer4 = withH(function (props) { return ({
43+
onChange: function (props) { return function (e) { }; },
44+
onSubmit: function (props) { return function (e) { }; }
45+
}); });
46+
enhancer4.onChange(null);

tests/baselines/reference/genericFunctionInference2.symbols

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,55 @@ const myReducer2 = combineReducers({
5454

5555
});
5656

57+
// Repro from #30942
58+
59+
declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;
60+
>withH : Symbol(withH, Decl(genericFunctionInference2.ts, 14, 3))
61+
>T : Symbol(T, Decl(genericFunctionInference2.ts, 18, 23))
62+
>U : Symbol(U, Decl(genericFunctionInference2.ts, 18, 25))
63+
>handlerCreators : Symbol(handlerCreators, Decl(genericFunctionInference2.ts, 18, 29))
64+
>HandleCreatorsFactory : Symbol(HandleCreatorsFactory, Decl(genericFunctionInference2.ts, 20, 28))
65+
>T : Symbol(T, Decl(genericFunctionInference2.ts, 18, 23))
66+
>U : Symbol(U, Decl(genericFunctionInference2.ts, 18, 25))
67+
>U : Symbol(U, Decl(genericFunctionInference2.ts, 18, 25))
68+
69+
type Props = { out: number }
70+
>Props : Symbol(Props, Decl(genericFunctionInference2.ts, 18, 78))
71+
>out : Symbol(out, Decl(genericFunctionInference2.ts, 20, 14))
72+
73+
type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };
74+
>HandleCreatorsFactory : Symbol(HandleCreatorsFactory, Decl(genericFunctionInference2.ts, 20, 28))
75+
>T : Symbol(T, Decl(genericFunctionInference2.ts, 22, 27))
76+
>U : Symbol(U, Decl(genericFunctionInference2.ts, 22, 29))
77+
>initialProps : Symbol(initialProps, Decl(genericFunctionInference2.ts, 22, 36))
78+
>T : Symbol(T, Decl(genericFunctionInference2.ts, 22, 27))
79+
>P : Symbol(P, Decl(genericFunctionInference2.ts, 22, 59))
80+
>U : Symbol(U, Decl(genericFunctionInference2.ts, 22, 29))
81+
>props : Symbol(props, Decl(genericFunctionInference2.ts, 22, 75))
82+
>T : Symbol(T, Decl(genericFunctionInference2.ts, 22, 27))
83+
>U : Symbol(U, Decl(genericFunctionInference2.ts, 22, 29))
84+
>P : Symbol(P, Decl(genericFunctionInference2.ts, 22, 59))
85+
86+
const enhancer4 = withH((props: Props) => ({
87+
>enhancer4 : Symbol(enhancer4, Decl(genericFunctionInference2.ts, 24, 5))
88+
>withH : Symbol(withH, Decl(genericFunctionInference2.ts, 14, 3))
89+
>props : Symbol(props, Decl(genericFunctionInference2.ts, 24, 25))
90+
>Props : Symbol(Props, Decl(genericFunctionInference2.ts, 18, 78))
91+
92+
onChange: (props) => (e: any) => {},
93+
>onChange : Symbol(onChange, Decl(genericFunctionInference2.ts, 24, 44))
94+
>props : Symbol(props, Decl(genericFunctionInference2.ts, 25, 15))
95+
>e : Symbol(e, Decl(genericFunctionInference2.ts, 25, 26))
96+
97+
onSubmit: (props) => (e: any) => {},
98+
>onSubmit : Symbol(onSubmit, Decl(genericFunctionInference2.ts, 25, 40))
99+
>props : Symbol(props, Decl(genericFunctionInference2.ts, 26, 15))
100+
>e : Symbol(e, Decl(genericFunctionInference2.ts, 26, 26))
101+
102+
}));
103+
104+
enhancer4.onChange(null);
105+
>enhancer4.onChange : Symbol(onChange, Decl(genericFunctionInference2.ts, 24, 44))
106+
>enhancer4 : Symbol(enhancer4, Decl(genericFunctionInference2.ts, 24, 5))
107+
>onChange : Symbol(onChange, Decl(genericFunctionInference2.ts, 24, 44))
108+

tests/baselines/reference/genericFunctionInference2.types

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,50 @@ const myReducer2 = combineReducers({
4747

4848
});
4949

50+
// Repro from #30942
51+
52+
declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;
53+
>withH : <T, U>(handlerCreators: HandleCreatorsFactory<T, U>) => U
54+
>handlerCreators : HandleCreatorsFactory<T, U>
55+
56+
type Props = { out: number }
57+
>Props : Props
58+
>out : number
59+
60+
type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };
61+
>HandleCreatorsFactory : HandleCreatorsFactory<T, U>
62+
>initialProps : T
63+
>props : T
64+
65+
const enhancer4 = withH((props: Props) => ({
66+
>enhancer4 : { onChange: (e: any) => void; onSubmit: (e: any) => void; }
67+
>withH((props: Props) => ({ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},})) : { onChange: (e: any) => void; onSubmit: (e: any) => void; }
68+
>withH : <T, U>(handlerCreators: HandleCreatorsFactory<T, U>) => U
69+
>(props: Props) => ({ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},}) : (props: Props) => { onChange: (props: Props) => (e: any) => void; onSubmit: (props: Props) => (e: any) => void; }
70+
>props : Props
71+
>({ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},}) : { onChange: (props: Props) => (e: any) => void; onSubmit: (props: Props) => (e: any) => void; }
72+
>{ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {},} : { onChange: (props: Props) => (e: any) => void; onSubmit: (props: Props) => (e: any) => void; }
73+
74+
onChange: (props) => (e: any) => {},
75+
>onChange : (props: Props) => (e: any) => void
76+
>(props) => (e: any) => {} : (props: Props) => (e: any) => void
77+
>props : Props
78+
>(e: any) => {} : (e: any) => void
79+
>e : any
80+
81+
onSubmit: (props) => (e: any) => {},
82+
>onSubmit : (props: Props) => (e: any) => void
83+
>(props) => (e: any) => {} : (props: Props) => (e: any) => void
84+
>props : Props
85+
>(e: any) => {} : (e: any) => void
86+
>e : any
87+
88+
}));
89+
90+
enhancer4.onChange(null);
91+
>enhancer4.onChange(null) : void
92+
>enhancer4.onChange : (e: any) => void
93+
>enhancer4 : { onChange: (e: any) => void; onSubmit: (e: any) => void; }
94+
>onChange : (e: any) => void
95+
>null : null
96+

tests/cases/compiler/genericFunctionInference2.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,18 @@ const myReducer1: Reducer<MyState> = combineReducers({
1313
const myReducer2 = combineReducers({
1414
combined: combineReducers({ foo }),
1515
});
16+
17+
// Repro from #30942
18+
19+
declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U;
20+
21+
type Props = { out: number }
22+
23+
type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] };
24+
25+
const enhancer4 = withH((props: Props) => ({
26+
onChange: (props) => (e: any) => {},
27+
onSubmit: (props) => (e: any) => {},
28+
}));
29+
30+
enhancer4.onChange(null);

0 commit comments

Comments
 (0)