ページへ戻る
− Links
印刷
TypeScriptのInterface
の編集 ::
NJF Wiki
xpwiki
:
TypeScriptのInterface
の編集
# g277fdfe の編集
ページ内容:
**new [#g277fdfe] newを使うとインスタンス製作時の引数を指定できる。ただし、そのInterfaceを継承するとエラーとなる。 interface ClockInterface { new (hour: number, minute: number); } class Clock implements ClockInterface { currentTime: Date; constructor(h: number, m: number) { } } これはエラー。 interface ClockStatic { new (hour: number, minute: number); } class Clock { currentTime: Date; constructor(h: number, m: number) { } } var cs: ClockStatic = Clock; var newClock = new cs(7, 30); こちらはOK。コンストラクタはstaticに属するが、newでチェックするのはインスタンスに属するものなのでエラーが出るらしい。わからないときはJavaScriptのコンストラクタの仕組みを思い出すか、そういう物だと思っておけばよい。
編集の要約:
Q & A 認証:
ページ更新時は次の質問にお答えください。(プレビュー時は必要ありません)
Q:
「京都」の読みがな?(ひらがなで)
A:
お名前:
タイムスタンプを変更しない
テキスト整形のルールを表示する
[1]
Links list
(This host) = https://njf.jp
(This host)
/cms/modules/xpwiki/?cmd=edit&help=true&page=TypeScript%E3%81%AEInterface