lib.d.ts types are too loose: provide a version without vars declared?
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- tooling
調査の方向性
ファイル、テスト、エントリポイントは指定されていません。まず、このジェネレーターがどのように lib.d.ts の宣言を生成するかを追跡し、次に既存のグローバル宣言を維持したまま、型のみのバリアントをどのように生成できるかを判断してください。ジェネレーターが要求された分離を公開し、その生成された出力がここで説明されているブラウザー対型のみのユースケースを検証できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
(Porting https://github.com/Microsoft/TypeScript/issues/20175)
A lot of teams have seen production bugs from trying to use code not available in older browsers. performance.now, for example, is listed in lib.d.ts but shouldn't be used on sites that support IE10 and don't polyfill performance.
Two other ways of getting around this class of problem without dropping browsers or adding polyfills (are there other good ones?) are:
- Manually banning scores of built-in types with TSLint
- Dropping
"dom"from"lib"intsconfig.json
Removing "dom" typings works great to enforce using only non-browser APIs (or dependency-injecting them where used), which is much better than calling APIs like performance.now and setTimeout willy nilly. However, you now need to manually re-write typings for all these native things as you go.
The solution would be much simpler if TypeScript exposed a form of lib.d.ts that included only the interfaces and types for all these constructs without the declare var/declare function.
Using setTimeout as an example, it's declared without a separate ISetTimeout interface in TypeScript's lib.d.ts:
declare function setTimeout(handler: (...args: any[]) => void, timeout: number): number;
declare function setTimeout(handler: any, timeout?: any, ...args: any[]): number;
interface WindowTimers extends Object, WindowTimersExtension {
// ...
setTimeout(handler: (...args: any[]) => void, timeout: number): number;
setTimeout(handler: any, timeout?: any, ...args: any[]): number;
}
If it were changed to provide an ISetTimeout it would be much easier to use setTimeout without a reliance on the browser+Node API.
interface SetTimeout {
(handler: (...args: any[]) => void, timeout: number): number;
(handler: any, timeout?: any, ...args: any[]): number;
}
interface WindowTimers extends Object, WindowTimersExtension {
// ...
setTimeout: SetTimeout;
}
// Only in the standard ("loose") version:
declare var setTimeout: SetTimeout;
Errata: I personally remove "dom" whenever possible.. but a lot of @types definitions assume it exists and it's a bit like whack-a-mole trying to fix typings on DefinitelyTyped to work in dom-less repos.
Edit: some DefinitelyTyped issues this causes:
- 主要言語
- TypeScript
- スター
- 740
- フォーク
- 474
- 平均マージ
- 2日 8時間
- マージ済み PR(30日)
- 15
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript-DOM-lib-generator のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
microsoft/TypeScript-DOM-lib-generator#2554 · コメント 6 件 ·
-
lib.d.ts bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
lib.d.ts bug
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#2154 · リアクション 1 件 ·
-
lib.d.ts bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#2107 · コメント 5 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#1675 · コメント 2 件 · リアクション 1 件 ·
microsoft/TypeScript-DOM-lib-generator の issue をすべて見る
似ている issue
-
Browser Waiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
getsentry/sentry-javascript#24577 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
agilepathway/label-checker#640 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
copse-dev/agent-pane#2953 ·
-
agentic-workflows
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
githubnext/rig#534 ·
-
automation missing-model model-sync provider:pioneer
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
anomalyco/models.dev#7701 ·