TypeScript: Declare a variable with type of object literal -
i trying find proper signature (current version of typescript 1.7) function should accept reference types, not primitives:
function onlyobject(x: ???) { if (typeof x !== 'object') { throw "bad arg!"; } }
so function above should work:
onlyobject({ }); onlyobject(new date()); onlyobject(new number(1)); onlyobject(null); onlyobject(function () { });
but fail in compile time:
onlyobject("awd"); onlyobject(1); onlyobject(false);
there isn't way express in language.
if you're feeling industrious, can add it, project accepting pull requests feature.
Comments
Post a Comment