-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
Typescript is unable to correctly determine that a function's return satisfies the specified type.
🔎 Search Terms
"Typescript expanding boolean into true/false" (#30029)
🕗 Version & Regression Information
v. 4.7.4
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about: YES
⏯ Playground Link
💻 Code
type SomeInferredFunctionType = (() => true) | (() => false);
// Gives TS error!
const test: SomeInferredFunctionType = () => {
return Math.random() > 0.5;
};🙁 Actual behavior
Typescript thinks test does not satisfy its given type when it does. Note, that it is possible (with much difficulty) to collapse SomeInferredFunctionType into the correct simplified type() => boolean when I have direct access to the type. However, in my codebase, the type is actually automatically inferred and I do not have access to it and I am just consuming it.
🙂 Expected behavior
Typescript should be able to determine that test satisfies the condition given by SomeInferredFunctionType
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug