Last active
December 11, 2016 04:55
-
-
Save onionmk2/65005463f0348184c0e536abe76ece07 to your computer and use it in GitHub Desktop.
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
/* | |
TSのインターフェースとは 以下2つのうちのいずれか。 | |
1. 抽象的な型。 プロパティの名前・型を指定した、JSオブジェクト。 | |
2. 引数と戻り値の型を明示した、Functionオブジェクト。 | |
http://stackoverflow.com/questions/41082804/does-typescript-interface-have-anonymous-and-named-function/41082880#41082880 | |
*/ | |
// 1. JSオブジェクト | |
interface JSobj { | |
a: number; | |
b: number; | |
/* c: anyと一緒なので(!)普通はこう書かない。implicit any チェックで死ぬ。*/ | |
// c: function; | |
strMethod: (z: string, w: string) => string; | |
} | |
const a: JSobj = { | |
a: 1, | |
b: 2, | |
strMethod(z: string, w: string) { | |
return z + w; | |
} | |
} | |
// 2. Functionオブジェクト | |
interface twoNumFunctionReturningNum { | |
(x: number, y: number): number; | |
} | |
const b: twoNumFunctionReturningNum = function c(z:number, w:number) { return z+w; }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment