Closed h3poteto closed 2 years ago
Thanks.
@h3poteto すみません,https://github.com/rhysd/electron-about-window/blob/master/src/lib.d.ts にまだ手書きの .d.ts が残っていて npm run build
で生成される .d.ts は src/lib.d.ts
を見ているので,どう改善されたのかよく分からなかったのですが,説明いただけませんでしょうか
For example, I want to specify app for the openAboutWindow function, but there is no definition of app in index.d.ts.
いえ,app
の定義は https://github.com/rhysd/electron-about-window/blob/185c4323055591e0ea3844653e3cb8a0ee3d5507/src/lib.d.ts#L36 にこの PR をマージする前からあるようですよ.
もともとpackage.jsonにtypingsの指定がなかったので,1.15.0までは,こちらのindex.d.tsが参照されていました.
https://github.com/rhysd/electron-about-window/blob/v1.15.0/index.d.ts
ここにはapp
の定義が存在しないため,ユーザはapp
を指定することができませんでした(typescriptの場合).
また,npmignoreに/src/*.ts
の記載があったため,src/lib.d.ts
はそもそもnpmにpublishされていません.そのため,たとえappの定義がsrc/lib.d.ts
に書いてあったとしても,npm install
したユーザがそれを参照することは不可能でした.
npm run build
により.d.ts
ファイルを生成するように変更しています.
src/lib.d.ts
はあるのですが,openAboutWindow
関数の定義はsrc/index.ts
に存在しており,この関数を定義するd.ts
が存在しませんでした.この変更により,src/index.ts
内のopenAboutWindow
関数の型定義ファイルsrc/index.d.ts
が生成されるようになります.ts
ファイル内に関数定義等を増やした場合も同様にd.ts
ファイルが自動生成されるようになりますAboutWindowInfo
を定義している.ts
ファイルが,src/lib.d.ts
しかないので,このファイルは引き続き必要ですsrc/index.d.ts
をpackage.jsonのtypingsに指定することで,ユーザがこのライブラリを参照したときに使われるd.ts
ファイルがsrc/index.d.ts
になります.
index.d.ts
が不要になるため,これを削除していますsrc/index.d.ts
が生成されても,npmignoreにより無視されてしまうので,src/*.d.ts
ファイルは無視せずにnpm publish
に含めるように変更しています.ご説明いただきありがとうございます.
なるほど,どうやらどこかの時点で /index.d.ts
と /src/index.d.ts
が重複して存在してしまい,/src/index.d.ts
のほうだけがメンテされてしまっている状態になっていたようですね(これは意図していませんでした).理由までは追ってませんが,おそらく他のプロジェクトと混同してしまっていたものと思います.
新しいバージョンをリリースしてこの変更を使えるようにします.
At the moment, there is a declaration file, but it is not the latest.
AboutWindowInfo
is defined in here, but it is not the same asindex.d.ts
.For example, I want to specify
app
for theopenAboutWindow
function, but there is no definition ofapp
inindex.d.ts
. https://github.com/rhysd/electron-about-window/blob/537d0855da73c8fbaf34bb652b54b3bd9f57be45/index.d.ts#L3-L21So I change tsconfig to generate declaration files from
.ts
, and use it as typings inpackage.json
. After this change,src/index.d.ts
is generated automatically usingnpm run build
.