#what does `string & {}` type exactly mean?

5 messages · Page 1 of 1 (latest)

livid elm
#

i sometimes see the type like for headers prop in vuetify's v-data-table component, and as far as i played with it in the playground it just looked behaving like a simple string.. but since there exists some code that explicitly specifies string & {}, it's got some special meaning (or trick maybe?) innit?

turbid valley
#

@livid elm Usually that's used to prevent string unions from collapsing to string to give better intellisense

dull burrowBOT
#
retsam19#0

Preview:```ts
type Collapses = "foo" | "bar" | string
// ^?
const x: Collapses = "" // no intellisense here

type DoesntCollapse = "foo" | "bar" | (string & {})
// ^?
const y: DoesntCollapse = ""```

livid elm