TypeScript 使うまでもない単体の JS ファイルでも d.ts を使いたい時ってあるじゃないですか。
そういうときのあれ。
例えば、 window に Docute というオブジェクトを生やしたこんな型定義があって。
// 面倒なので一部だけ
type DocuteOptions = {
target?: string;
title?: string;
};
interface Docute {
new (options?: DocuteOptions): this;
}
export declare global {
interface Window {
Docute: Docute;
}
}
もう何もかも面倒で tsconfig.json すら作りたくないけど型チェックだけ使いたいとき、
下のようにすれば一応動く
// @ts-check /// <reference path = "../@types/globals.d.ts" /> new Docute(...); // 型チェックも動く
ということで、怠惰なメモでした。