TypeScript · Senior · Question 64 of 75

How do you get the type of a module's exports without importing its values?

type Api = typeof import('./api');

Explanation

This is handy for lazy-loaded modules: you can type the result of a dynamic import() without bundling it eagerly.

Further reading

Problem with a question

TypeScript · Senior · question 64

Test yourself

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

Take this quiz