Last active
June 27, 2021 03:41
-
-
Save pentamania/8a096e57526350575cad4170c5fe6421 to your computer and use it in GitHub Desktop.
typescriptに怒られない形でphina-esmの拡張を行う方法(仮)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Object2D } from "phina.js"; | |
// 拡張宣言部分: 拡張したいクラス型定義へのパス | |
declare module "phina.js/types/app/object2d" { | |
// プロトタイプ拡張する場合 | |
export interface Object2D { | |
/** | |
* [ここに詳細] | |
*/ | |
piyo(): void; | |
} | |
// static拡張する場合 | |
export namespace Object2D { | |
/** | |
* [ここに詳細] | |
*/ | |
function piyoStatic(): void; | |
} | |
} | |
// 実装部分 | |
Object2D.prototype.piyo = function () { | |
console.log("piyo"); | |
}; | |
Object2D["piyoStatic"] = function () { | |
console.log("piyopiyo"); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 最初に読み込み | |
import "./extendPhinaEsModule"; | |
import { phina, Object2D } from "phina.js"; | |
phina.main(() => { | |
const obj = new Object2D(); | |
obj.piyo(); | |
Object2D.piyoStatic(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment