0
在下面的代碼片段中,TypeScript可以表達「a是某個對象,但不是布爾,數字,字符串,數組或函數」?可以用Typescript表示「一個是某個對象」嗎?
var a:Object;
a = {
just: "some object",
n: 1,
};
// what type does `a` need to disallow the following
a = ["array", 2, {}];
a = "nostring";
a = false;
a = 0;
a =()=> { return "i am a function!"};
var button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = function() {
alert(a.toString());
};
document.body.appendChild(button);