Types You Don't Control 12 exercises
Problem

Declaring Module Types in TypeScript

In this exercise, we're going to examine a new piece of syntax, which is used to declare the types of modules in TypeScript.

Here we're importing a function myModuleFunc from my-module:


import { myModuleFunc } from "my-module"; // red squiggly line under "my-module"

However, there

Loading exercise

Transcript

00:00 In this exercise, we're going to look at a new piece of syntax, which helps you declare the types of modules. We have here a MyModuleFunc, which we're importing from MyModule, except that in this situation, MyModule doesn't actually exist on the file system. So MyModule here is basically just a random string.

00:18 This could, like, there are some situations where this comes up, could be like a virtual module, or you're like sim linking to a certain workspace or a path or something like that. But we just want to use this as an exercise to learn some new syntax. So we want MyModuleFunc to be of a certain type. We want it just to be a function with no parameters that returns void.

00:37 Your job is to try to work out the syntax that you need in order to declare this module, and that might give you a hint. So yeah, you might need to use a declaration file. Certainly, my solution uses a declaration file. And I think that's all the information I'm going to give you.

00:55 Declaration file, declare module, and best of luck.