Elektrine lite

← Feed

@Karjalan@lemmy.world

2026-11-07 19:56 UTC

We use typescript and try very hard not to return any… But 95% of out back ends api returns are type bob: Type || undefined So we have to cater for that almost everywhere and half the time it feels like “strong typing” is a waste of effort. But I still prefer the relative certainty of typescript

Replies (3)

  • @kkj@lemmy.dbzer0.com 2026-11-07 23:47

    So, an equivalent to C#'s Type? or Python’s Optional[Type]? That’s still a lot better than nothing. You aren’t going to get an array when you asked for a float, for example.

    Open ##5500092

  • @wucking_feardo@lemmy.world 2026-11-08 06:34

    I don’t know shit about your codebase. But it sounds like you aren’t abstracting your API calls property. Ideally you have an API Client that consumes those blobs and converts them to some generically typed return value. On top of that you have your actual API, which accepts actions and returns actual objects/collections, or just fucking fails and bubbles up as a generic error because something’s gone fucking wrong.

    Open ##5501183

  • @bitfucker@programming.dev 2026-11-08 15:36

    You may need a tagged type. It is done on our code base such that currency of one type can’t be operated on currency of another type. The basic is that TAG !== TAG because even if the underlying type is the same (number), they are of different types on the type system. See also type-fest library that provide a ton more helper type like that

    Open ##5502808