Lurker News
Back to discussion

Comment by ricksharp

ricksharp3 replies#
Object.keys() is always frustrating.

Also, the array access not returning an optional type (I wish there was a strict option for that) often gets me.
We need a middle ground: “TypeStrict“ that can clean up some of the edge cases.
If you need strict integers, you can create your own fake type:
type Int32 = number & {__type:'Int32'};
I do this with strings sometime when I want a string subtype that can’t be accidentally assigned by a normal string.

williamdclt2 replies#
For anybody interested in this technique: the googleable term is "branding". It's bringing some nominal typing into TS's structural typing
ricksharp#
Cool, I never knew what that was called. Thanks!
ricksharp#
Awesome!

I was just searching for that and all I could find were old github issues saying it was working as intended.
Thank you!