-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Description
Bug Report
π Search Terms
"object" | "{}"
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about object & {}.
β― Playground Link
Playground link with relevant code
π» Code
type A = {}
const a0: A = undefined // error
const a1: A = null // error
const a2: A = 2 // ok
const a3: A = 'hello world' //ok
const a4: A = { foo: 'bar' } //ok
const a5: A = () => undefined //okconst X = {} // X: {}
type D = typeof X // D = {}const Y = new Object() // Y: Object
type E = typeof X // E = {}interface F<T extends object = {}> {
prop: T;
}π Actual behavior
I have found at least few issues with {} type, all presented in playground and code samples above:
- Is undocumented (or I couldn't find it in docs) and confusing - looks like object literal but can have primitives assigned.
- Object literal has a
{}type assumed while it should rather beObject/object. new Objecthas a{}type assumed while it should rather beObject/object.{}type can be assigned to more narrowobjecttype, which should not be possible.
π Expected behavior
{} type is documented, cannot be assigned to more narrow object type and is not assumed when used with typeof <some_object>.
Metadata
Metadata
Assignees
Labels
No labels