Open
Description
TypeScript Version: 3.1.0-dev.20180810
Search Terms: react-redux connect type inference
I've noticed this issue while upgrading from v3.0.3. Type inferrence got broken on some of redux's connect
calls. I was able to isolate the issue (see the code below). The issue is reproducible on @next
and @latest
. I ran some regression tests and was able to narrow it down to 3.1.0-dev.20180810
where the bug was introduced. The last version where the code works as expected was 3.1.0-dev.20180809
.
Code
type MapStateToProps<TStateProps> = () => TStateProps;
type MergeProps<TStateProps, TMergedProps> = (stateProps: TStateProps) => TMergedProps;
function connect<TStateProps = {}, TMergedProps = {}>(
mapStateToProps: MapStateToProps<TStateProps>,
mergeProps: MergeProps<TStateProps, TMergedProps>) {
}
connect(() => ({ time: 123 }), ({ time }) => ({
time,
doSomething() {
},
}))
Expected behavior: compiles without errors
Actual behavior: error TS2459: Type 'TStateProps' has no property 'time' and no string index signature.
Playground Link: here
Somehow these examples compile without problem though:
// no 'expression body' in C# terms
connect(() => ({ time: 123 }), ({ time }) => {
return {
time,
doSomething() {
},
}
})
// no 'time' on TMergedProps
connect(() => ({ time: 123 }), ({ time }) => ({
doSomething() {
},
}))
// property instead of a function
connect(() => ({ time: 123 }), ({ time }) => ({
time,
doSomething: () => {
},
}))