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
It is great to know that the next TypeScript will come with Union Types. This will allow to tighten up those previously any parameter definitions that accept more than one type. One thing that I wanted to bring up which is very common in JavaScript is parameters or objects that take documented string constants. For example assume we have the following function that takes a width and a color:
changeStyle(width,color);
My suggestion is let us include string constants in Union Types, so that we can have:
Then we can have tools suggest those especial strings in tooltips or intellisense, and catch more errors. For example:
shape.changeStyle(120,0xFFFFFF);// OKshape.changeStyle("small","magenta");// OKshape.changeStyle("16pt","yellow");// error on widthshape.changeStyle(stringObj,"red");// OK, if string variable is passed, just allow it
Thanks!
The text was updated successfully, but these errors were encountered:
It is great to know that the next TypeScript will come with Union Types. This will allow to tighten up those previously
any
parameter definitions that accept more than one type. One thing that I wanted to bring up which is very common in JavaScript is parameters or objects that take documented string constants. For example assume we have the following function that takes awidth
and acolor
:My suggestion is let us include string constants in Union Types, so that we can have:
Then we can have tools suggest those especial strings in tooltips or intellisense, and catch more errors. For example:
Thanks!
The text was updated successfully, but these errors were encountered: