1. 程式人生 > >typescript 接口的新認識

typescript 接口的新認識

int bsp sss cti result span wid offset sca

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;

offsetTop: number;
style: CSSStyleDeclaration,
offsetWidth: number;
}

interface Window {
startY: number;
Transform: (el: Element) => void;
yhaoTouch: (el: any) => void;
isscroll: boolean;
}

typescript 接口的新認識