You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Trying to apply Type Assertions for a function that takes optional arguments. when the optional arguments are not provided, it throws errors. will it be nice if assert.argumentTypes check and only apply type checking if optional argument is not undefined?
in the example below, value argument is optional and type is number.
My suggestion is, validate type only if an optional argument is supplied.
exportclassEnumItem{// constructor(name: string, {value} = {}, value: number) { //TODO want to use this constructor(name: string,{value =Infinity},value: number){//workaroundthis.name=name;// this.value = (value) ? value: Symbol(name); //want to use this this.value=(value===Infinity) ? Symbol(name) : value;//workarounddeletearguments[1].value;Object.assign(this,arguments[1]);Object.freeze(this);}toString(){returnthis.name;}valueOf(){returnthis.value;}}console.log('EnumItem1',newEnumItem('xname',{value:2}));console.log('EnumItem2',newEnumItem('xname',{description:'ssss'}));