microsoft / microsoft/TypeScript

json files should be usable in .d.ts files without breaking things

オープン
#24,744 コメント 9 件 リアクション 5 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Search Terms

resolveJsonModule import definition

Suggestion

As a .json file is a static resource, it should be able to be referenced in a global.d.ts file for example without that file being automatically treated as a module. The reason for this is that a .json file may be used to simply enforce valid translation keys, and you shouldn't need to suck the whole .json file into the transpilation process to do that.

Use Cases

Example:

import translations from "../assets/translations/en-AU.json"
type $translate = {
    instant: (translationKey: keyof typeof translations) => string,
    use: Function,
    proposedLanguage: Function
}

The downside of the current method again is that the translations file is output in the transpilation process, which is wasteful if the file is large.

What the above code snippet is trying to achieve, should be allowed in a .d.ts file without breaking global declaration functionality.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、global.d.ts、.d.tsファイル、../assets/translations/en-AU.jsonを含む例を再現し、その後、現在、宣言ファイルとJSONインポートがどのように扱われているかを調べます。完了条件は、グローバル宣言を壊したり、JSONをトランスパイル出力に不必要に含めたりすることなく、その例から翻訳キー用のJSONを参照できることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。