3 ms·
Type erasure is only safe if the whole program is statically typed though - you are still going to need to use runtime checks if you want to interface with dyna
by ufo 12y ago
Type erasure is only safe if the whole program is statically typed though - you are still going to need to use runtime checks if you want to interface with dynamic code.
- slashnull 12y agoWell yeah nobody talked about removing JS's duck typing algo.
- oyvindkinsey 12y agoBased on the inference, we can imagine a case where Flow would flag certain boundaries as 'unsafe', allowing a transform to inject dynamic type safety checks using the same type information Flow has available. For instance, you could imagine a function calling into some unknown api, where we would need to constrain the type of the variable to the expected one to avoid `any` being applied to it. While the library files do provide typing of external dependencies, this doesn't protect you from bugs in those libraries! The same applies to api's that are explicitly typed as `any`, but which should return a certain type. Having Flow add a dynamic assertion on the type here would allow the rest of the program to remain type safe, knowing that a violation is guaranteed to halt execution. While dynamic strong typing is also used at Facebook, we're not quite ready to launch this as an extension to Flow.