3 ms·
Typescript (an extension to JS that adds type-safety) essentially does option 3 as well. As the sibling noted, there are instances during runtime where the typ
by whoisthemachine 11y ago
Typescript (an extension to JS that adds type-safety) essentially does option 3 as well.
As the sibling noted, there are instances during runtime where the type checking fails, especially because Typescript is compiling to Javascript. I have had moments where a numeric observable in KnockoutJS had to be forced to a number when receiving a new value; the form that the observable is bound to is simply returning a string, and while the TS interface for KnockoutJS says the observable is a number, the actual JS doesn't care and just returns what the form gives it.
In some ways this is a failing of Typescript; it shouldn't allow strongly-type interfaces to be wrapped around JS that can return varying types.
- spankalee 11y agoTypescript doesn't insert any runtime type checks at all. It also can't know that interfaces for raw JS are typed wrong, because Typescript is only a static checker. Dart in checked mode does insert runtime type checks, but leaves them out in production mode.