microsoft / microsoft/TypeScript
JSDoc-typed node modules require special configuration in consumers to be useful
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
It looks like an ongoing goal for TS is to recommend JSDoc as the recommended way to give type-checking to raw JS users. As a user I am not a huge fan of this approach but I'll try to be objective in this issue.
If I write a node module js-lib as raw javascript typed with jsdoc, it will appear as untyped to consumers of my module unless they specifically opt in to JS type checking.
Example:
+-js-lib
| +-index.js
| +-package.json
|
+-ts-consumer
+-index.ts
+-package.json
+-tsconfig.json
js-lib/index.js
/**
* @param {string} s
* @returns {number}
*/
module.exports = function test(s) { return parseInt(s) };
js-lib/package.json
{
"name": "js-lib",
"main": "index.js"
}
ts-consumer/index.ts
import test = require('../js-lib');
// index.ts(1,23): error TS6143: Module '../js-lib' was resolved to '/Users/jarrad/src/personal/ts-test/lib/js-index.js', but '--allowJs' is not set.
import test = require('js-lib'); // after npm install ../js-lib
// index.ts(1,23): error TS7016: Could not find a declaration file for module 'lib'. '/Users/jarrad/src/personal/ts-test/lib/index.js' implicitly has an 'any' type.
// Try `npm install @types/lib` if it exists or add a new declaration (.d.ts) file containing `declare module 'lib';
test("test");
ts-consumer/tsconfig.json
{
"compilerOptions": {
"strict": true
}
}
It should be possible for me to make my js-lib usable to Typescript authors without them having to configure their own project with allowJs and checkJs.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
例の js-lib/index.js、js-lib/package.json、ts-consumer/index.ts、ts-consumer/tsconfig.json を使って問題を再現します。まず、コンパイラが JavaScript Node モジュールをどのように解決し、TypeScript のコンシューマー向けの型情報をどのように見つけるかを追跡します。コンシューマーが allowJs と checkJs を有効にしなくても、JSDoc で型付けされたモジュールが有用な型を提供できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, node.js, typescript
- 領域
- compilers, developer-experience, tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100