-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: flag: exactOptionalPropertyTypesBugs specific to enabling this flagBugs specific to enabling this flag
Milestone
Description
π Search Terms
exactOptionalPropertyTypes
object spread
ternary
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about exactOptionalPropertyTypes, object spread.
β― Playground Link
π» Code
type Foo = {
parentId?: string
}
declare const requestBody: Foo;
let target: Foo;
// shows expected error due to ExactOptionalPropertyTypes
target = { parentId: requestBody.parentId };
// missing error when using spread and ternary
target = { ...(true ? { parentId: requestBody.parentId } : {}) }; // BUG
const { parentId } = requestBody;
target = { ...(true ? { parentId: parentId } : {}) }; // BUG
// error appears correctly if value is not a property accessed from an object
const parentId2 = '' as string | undefined;
target = { ...(true ? { parentId: parentId2 } : {}) };π Actual behavior
The expected error is silenced only in the specific case that combines object spread, ternary, and accessing an optional property from an object, although the types are always recognized correctly with | undefined.
π Expected behavior
All scenarios demonstrated in the code snippet are expected to show the same error.
Additional information about the issue
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: flag: exactOptionalPropertyTypesBugs specific to enabling this flagBugs specific to enabling this flag