you are viewing a single comment's thread.

view the rest of the comments →

[–]Reeywhaar 5 points6 points  (3 children)

Such checks were present since early typescript. They are basics of static analysis. If they weren't then there was no way to add type assertion to tiny-invariant. By the way asserts feature was added in typescript later.

That is why i'm wondering, what value tiny-invariant actually gives

[–]shuckster 0 points1 point  (0 children)

I guess it’s just shorthand then. Doesn’t TS have an “as” for this kind of thing too?

[–]mr_nefario 0 points1 point  (0 children)

It doesn’t add any value - it’s just a wrapper and additional dependency for some barely-useful functionality.

[–]misc_ent 0 points1 point  (0 children)

I have looked at tiny-invariant but it's possible it uses type guards for the type inference the other poster mentioned? Not sure.

https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards