1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TypeScript型定義ファイルの置き場所

Last updated at Posted at 2021-05-22

他にもやり方はあるようだが、一つの簡単なやり方。

外部に export する関数に対して

// src/main.ts
export function someFunc(a: number): string {
  return `Got ${a}`
}

index.d.ts に型定義を書いて、どこかに置く。例えば、src/index.d.ts

// src/index.d.ts
export function someFunc(a: number): string;

そして package.jsonmain に外部に export するファイルへのパス、typeings に型定義ファイルへのパスを指定する。

src/main.tsdist/main.js にトランスパイルされるとするなら、

// package.json
{  
  "main": "dist/main.js", 
  ...
  "typings": "src/index.d.ts",
  ...
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?