Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Last active December 11, 2016 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onionmk2/65005463f0348184c0e536abe76ece07 to your computer and use it in GitHub Desktop.
Save onionmk2/65005463f0348184c0e536abe76ece07 to your computer and use it in GitHub Desktop.
/*
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