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
I saw in your Description that you say These solutions bring static typing, which means it only validate your code at build time, not runtime. Once compiled in JavaScript and run in the browser, there is no longer any guarantee that the variables you are working with have the intended types. As I can see from TypeScript Docs the Advanced Types - User-Defined Type Guards are exactly the case to detect the correct type of a variable during runtime, isn't it?
The text was updated successfully, but these errors were encountered:
Not really, no. This feature is meant to give indications to TypeScript compiler that when you call a function at runtime like isFish (a function that you have to write yourself, that's why it is called "User Defined"), you bring the guarantee to TypeScript that the code under this if() branch has the Fish type, and TS can narrow down the union type.
TypeScript does not provide runtime checking, but the developer can do it manually and then need to inform TypeScript that he has done the job 😄
You can imagine that ObjectModel could be used as a giant User-defined type guard for any TypeScript class. In theory we could use both ObjectModel and TypeScript (though I obviously do not see the point), then put everywhere "It's okay TypeScript, ObjectModel has done the type-checking job, you can trust it."
I saw in your Description that you say
These solutions bring static typing, which means it only validate your code at build time, not runtime. Once compiled in JavaScript and run in the browser, there is no longer any guarantee that the variables you are working with have the intended types.
As I can see from TypeScript Docs theAdvanced Types - User-Defined Type Guards
are exactly the case to detect the correct type of a variable during runtime, isn't it?The text was updated successfully, but these errors were encountered: