How To Use TypeScript’s Built-In ConstructorParameters Type
A dive into TypeScript’s ability to infer constructor parameters, for all of your class-based object-oriented programming needs. Read this one if you need a refresher on JavaScript classes 😉
TypeScript’s Type for Typing Constructor Parameters
When it comes to TypeScript, the language isn’t just about adding static types to modern JavaScript. It’s also about augmenting your JavaScript with a healthy, rich diet of built-in utility types to make your coding life easier. Among these utilities is the built-in ConstructorParameters
type.
Ever been in a situation where you wanted to know the exact arguments required by a constructor? I honestly never had before researching this article! But if you’re coming from another programming language like Java or PHP, writing classes will be natural for you, and they’re valid TypeScript! ConstructorParameters
is what you need if you’re dealing with constructors.
Quick Review: Constructors and Classes in JS/TS
First, let’s review the key concepts that we’re working with when we discuss JavaScript classes, and…