Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question Regarding static vs dynamic typing #46

Closed
Mojo90 opened this issue Mar 1, 2017 · 2 comments
Closed

Question Regarding static vs dynamic typing #46

Mojo90 opened this issue Mar 1, 2017 · 2 comments

Comments

@Mojo90
Copy link

Mojo90 commented Mar 1, 2017

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?

@sylvainpolletvillard
Copy link
Owner

sylvainpolletvillard commented Mar 1, 2017

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."

@Mojo90
Copy link
Author

Mojo90 commented Mar 1, 2017

got it, thank you!

@Mojo90 Mojo90 closed this as completed Mar 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants