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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -