31
loading...
This website collects cookies to deliver better user experience
as any
until the transpiler stopped complaining.user.phone
or user.phoneNumber
?" 🤔)// what can we assign to it?
const foo: Bar = ???
Bar
.number | string
is the set of all numbers and strings. class Person {
name: string
}
// We didn't use the "new" keyword
const person: Person = {
name: 'Jame'
}
type File = {
name: string
extension: string
}
type Folder = {
name: string
color: string
}
type DesktopItem = File | Folder
DesktopItem
contains all the objects that either have the properties (name and type) of File
or Folder
.const item: DesktopItem = couldBeFileOrFolder
// should work, right?
givenItem.extension
File
has that property and the specific type of item
could be Folder
.name
of type string
, because it is the only property that they have in common.keyof (A&B) = (keyof A) | (keyof B)
keyof (A|B) = (keyof A) & (keyof B)
never
is the empty set and unknown
is the universal set.Y
is assignable to a type X
if Y
is a subtype of X
.