-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
Description
Bug Report
π Search Terms
object type condition parenthesis
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ.
β― Playground Link
Playground link with relevant code
π» Code
// This throws an error as expected because "Spread types may only be created from object types"
const invalid = { ...(false) }
// This does not throw even though the value in parenthesis would also be resolved to `false` which
// is a side effect of wrong type detection. This assignment is allowed because Typescript cannot detect
// that there is a possibility that the value inside the parenthesis would be `false`.
const valid = { ...([].length > 1 && {}) }
const wrongTypeDetection = ([].length > 1 && {}) // type of wrongTypeDetection is {} instead of false | {}
π Actual behavior
Type of const wrongTypeDetection = ([].length > 1 && {})
is {}
π Expected behavior
Type of const wrongTypeDetection = ([].length > 1 && {})
should be false | {}
Metadata
Metadata
Assignees
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options