摘要:
class Song { constructor(public title: string, public duration: number) { } } class Playlist { constructor(public name: string, public songs: Song[]) 阅读全文
摘要:
"Record" repersent key-value pair. type MyRecord<K extend string, T> = { [P in K]: T } Record key should be string. array[0] in javascript, even we gi 阅读全文
摘要:
For example we have interface: interface Person { name: string, age?: number } 'age' is an optional prop. // will have an error since person.age is us 阅读全文
摘要:
type MyPartial<T> = { [P in keyof T]?: T[P] } 'in' like a loop. Usage: function updatePerson(person: Person, prop: MyPartial<Person>) { return {...per 阅读全文
摘要:
const person = { name: "wan", age: 28 } type Person = typeof person type PersonKeys = keyof person // "name" | "age" type PersonKTypes = Person[Person 阅读全文
摘要:
In Javascript, you know typeof: typeof [] // object typeof "" // string In Typescript it is more smart: const person = { name: "wan", age: 28 } type P 阅读全文