Я могу использовать import("mod")
для доступа к немодульным скриптам.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
Вот так:
declare module 'ui-library' {
export const Icon: React.FC;
}
var card:Object = {name:"Tom"};
trace("age" in card); // return false
trace("name" in card); // return true
Попробуйте этот оператор: "в"
hasOwnPropery
- это один из способов его проверки. Возьмем для примера:
var dict: Dictionary = new Dictionary();
// this will be false because "foo" doesn't exist
trace(dict.hasOwnProperty("foo"));
// add foo
dict["foo"] = "bar";
// now this will be true because "foo" does exist
trace(dict.hasOwnProperty("foo"));
Самый быстрый путь может быть самым простым:
// creates 2 instances
var obj1:Object = new Object();
var obj2:Object = new Object();
// creates the dictionary
var dict:Dictionary = new Dictionary();
// adding the first object to the dictionary (but not the second one)
dict[obj1] = "added";
// checks whether the keys exist
var test1:Boolean = (dict[obj1] != undefined);
var test2:Boolean = (dict[obj2] != undefined);
// outputs the result
trace(test1,test2);
Попробуйте это:
for (var key in myArray) {
if (key == myKey) trace(myKey+' found. has value: '+myArray['key']);
}