Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate declaration files from .ts, and use it as typings #70

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

h3poteto
Copy link
Contributor

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 as index.d.ts.

For example, I want to specify app for the openAboutWindow function, but there is no definition of app in index.d.ts.

export interface AboutWindowInfo {
icon_path: string;
product_name?: string;
package_json_dir?: string;
about_page_dir?: string;
bug_report_url?: string;
bug_link_text?: string;
copyright?: string;
homepage?: string;
description?: string;
license?: string;
win_options?: Electron.BrowserWindowConstructorOptions;
css_path?: string | string[];
adjust_window_size?: boolean;
open_devtools?: boolean;
use_inner_html?: boolean;
use_version_info?: boolean | [string, string][];
show_close_button?: string;
}

So I change tsconfig to generate declaration files from .ts, and use it as typings in package.json. After this change, src/index.d.ts is generated automatically using npm run build.

@rhysd
Copy link
Owner

rhysd commented Oct 25, 2021

Thanks.

@rhysd rhysd merged commit d2830ba into rhysd:master Oct 25, 2021
@rhysd
Copy link
Owner

rhysd commented Oct 25, 2021

@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 の定義は

app?: Electron.App;
にこの PR をマージする前からあるようですよ.

@h3poteto
Copy link
Contributor Author

h3poteto commented Oct 25, 2021

前提

もともと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したユーザがそれを参照することは不可能でした.

今回の変更

  1. tsconfigを変更し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しかないので,このファイルは引き続き必要です
  2. 上記で生成されるsrc/index.d.tsをpackage.jsonのtypingsに指定することで,ユーザがこのライブラリを参照したときに使われるd.tsファイルがsrc/index.d.tsになります.
    • このためトップディレクトリのindex.d.tsが不要になるため,これを削除しています
  3. src/index.d.tsが生成されても,npmignoreにより無視されてしまうので,src/*.d.tsファイルは無視せずにnpm publishに含めるように変更しています.

@rhysd
Copy link
Owner

rhysd commented Oct 25, 2021

ご説明いただきありがとうございます.

なるほど,どうやらどこかの時点で /index.d.ts/src/index.d.ts が重複して存在してしまい,/src/index.d.ts のほうだけがメンテされてしまっている状態になっていたようですね(これは意図していませんでした).理由までは追ってませんが,おそらく他のプロジェクトと混同してしまっていたものと思います.

新しいバージョンをリリースしてこの変更を使えるようにします.

@rhysd
Copy link
Owner

rhysd commented Oct 25, 2021

v1.15.1 をリリースしました

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants