typescript 接口的新認識
阿新 • • 發佈:2018-04-05
int bsp sss cti result span wid offset sca
offsetTop: number;
style: CSSStyleDeclaration,
offsetWidth: number;
}
interface 用於接收服務器的數據。
eg:
interface mmmmm {
x: string,
y: number,
z: number,
select: KnockoutObservable<boolean>
}
$.post(url + ‘/app.ashx‘,
ko.utils.stringifyJson( {x: ‘12‘, y: 1, z: 10 }),
function (response) {
var result = $.parseJSON(response);
alert(‘ok‘);
var mm = <mmmmm>result;
mm.select = ko.observable(false);
alert(mm.select());
});
不會在js中出現。
可擴展的對象,定義為接口。可在ts中使用。不會報錯。
interface Element {
scaleX: number;
scaleY: number;
offsetHeight: number;
style: CSSStyleDeclaration,
offsetWidth: number;
}
interface Window {
startY: number;
Transform: (el: Element) => void;
yhaoTouch: (el: any) => void;
isscroll: boolean;
}
typescript 接口的新認識