TypeScript advanced types and utilities
Lao Yuan Front End Pioneer
// Daily Front End Night Talk No. 467
// Main body: 1200 words
// Estimated reading time: 10 minutes
Let's take a look at today's outline together, and hope that these advanced types and utilities can help you save some development time:
“
- ConstructorParameters
- Exclude
- Extract
- InstanceType
- NonNullable
- Parameters
- Partial
- Readonly
- ReadonlyArray
- Pick
- Record
- Required
- ReturnType
1. ConstructorParameters: a tuple of parameter types of the class constructor
class User {
constructor(uname: string, age: number) {}
}
type TCtor = ConstructorParameters<typeof User>;
function init(...info: TCtor) {
const [name] = info;
console.log('[name]', name);
}
init('京程一灯