3 ms·
Can TypeScript do runtime enforcement at the boundaries between typed and untyped code, though?
by TazeTSchnitzel 11y ago
Can TypeScript do runtime enforcement at the boundaries between typed and untyped code, though?
- swax 11y agoNo, and you wouldn't want the overhead. You can turn on warnings though if you want to make sure all your code is typed on compile. After compiling all type definitions are stripped and you're left with plain javascript.
- msoad 11y agoHow do you enable warnings?
- DCoder 11y agoswax is probably referring to the compiler option "noImplicitAny", which can literally turn variables whose type is not explicitly specified and cannot be inferred from their declaration as errors, instead of assuming they have the transparent `any` type.
- marcoperaza 11y agoThis is a neat idea. Even with a significant perf hit, it could be used during development, testing, and debugging. You should propose this to the Typescript team! https://github.com/Microsoft/TypeScript/issues https://github.com/Microsoft/TypeScript/issues
- TazeTSchnitzel 11y agoI recall some paper from people who had already implemented it. Edit: It might have been this one: http://research.microsoft.com/apps/pubs/?id=224900 http://research.microsoft.com/apps/pubs/?id=224900
- pspeter3 11y agoYou can add type safe guards which uses reflection at runtime.
- richdougherty 11y agoSomething like this? "Safe TypeScript: Safe and Efficient Gradual Typing for TypeScript" http://research.microsoft.com/apps/video/default.aspx?id=226836 http://research.microsoft.com/apps/video/default.aspx?id=226...
- TazeTSchnitzel 11y agoThat was precisely the paper I was thinking of.