typescript optional parameter type check -


i've got function (func) on class (myclass) optional parameter. type of optional parameter (myinterface) has optional properties.

i expected compiler error when call foo primitive number. thats not case. why that? , there way tell type system mark error?

interface myinterface {     foo?: string }  class myclass {     func(b?: myinterface) : void {} }  let c = new myclass(); c.func(); c.func({ foo: 'bar' }); c.func({ foo: 30 });       // compiler error: ok c.func({}); c.func(60);                // no compiler error: not expect 

the reason happens number compatible {}. (for example, imagine argument of type {tofixed: (n: number) => string}, too, compatible number).

you can think way: you can number, {foo?: string}.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -