-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version:
2.8.1, 2.9.2, 3.0.0-dev.20180628
Search Terms:
conditional type inference
Code
// very contrived code to demonstrate the issue
// this conditional type trips type inference
type Action<P> = P extends void
? { type: string }
: { type: string, payload: P }
interface Dispatch {
// this conditional type seems to have no negative impact on type inference
<P>(action: Action<P>): P extends void ? undefined : P
}
declare const dispatch: Dispatch
const numberAction: Action<number> = {
type: 'dummy',
payload: 0,
}
// infered result type is {}, expected one is number
, numberResult: number = dispatch(numberAction)
const voidAction: Action<void> = {
type: 'dummy',
}
// seems infered P is {}, so it is not allowed to pass voidAction to dispatch
, voidResult: undefined = dispatch(voidAction)Expected behavior:
Type checking succeedes
Actual behavior:
Type checking fails for two places:
- numberResult: number = dispatch(numberAction)
- voidResult: undefined = dispatch(voidAction)
Playground Link:
Playground
I believe this sample captures the issue but just in case there is a more verbose sample with original types
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed