TypeScript · Middle · Question 63 of 75

How do you get the instance type and constructor arguments of a class?

type Svc = InstanceType<typeof ApiService>;
type Args = ConstructorParameters<typeof ApiService>;

Explanation

ApiService as a type already means the instance type; typeof ApiService is the constructor itself.

Further reading

Problem with a question

TypeScript · Middle · question 63

Test yourself

Take the TypeScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz