[Typescript] The declare module Syntax in TypeScript

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

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

 

Let's start by creating a new declaration file called my-module.d.ts inside of the src directory.

Inside the file, we'll use the declare module syntax to define a module and indicate what it exports. To match the test from the challenge, we'll export a function named myModuleFunc that returns void:

// inside src/my-module.d.ts

declare module "my-module" {
  export const myModuleFunc: () => void;
}

 

posted @ 2024-08-08 19:17  Zhentiw  阅读(23)  评论(0)    收藏  举报