-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
🔎 Search Terms
union record narrow type guard
🕗 Version & Regression Information
- This changed between versions 4.7.4 and 4.8.2
⏯ Playground Link
💻 Code
function isObject<T>(it: T): it is T & Record<string, unknown> {
return Object.prototype.toString.call(it) === "[object Object]";
}
declare function test(arg: Record<string, any>): void
declare const arg: (string | number | { a: "b" });
if (isObject(arg)) {
// arg is:
// - TS 4.7: {a: "b"}
// - TS 4.8: (string | number | { a: "b" }) & Record<string, unknown>
test({ ...arg }) // ERROR: Spread types may only be created from object types.(2698)
}🙁 Actual behavior
arg stays as some intersection type, which TS does not recognize as an object type.
🙂 Expected behavior
arg gets narrowed to {a: "b"}
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