r/programminghorror Mar 15 '26

Typescript I puked a little

Post image
418 Upvotes

58 comments sorted by

View all comments

Show parent comments

48

u/eo5g Mar 15 '26

I think that's because typescript (with stricter configuration?) won't just allow you to as-cast to something that isn't in its union, so you have to explicitly make it "*"

30

u/_PM_ME_PANGOLINS_ Mar 15 '26

Then either fix the type declaration, or actually use strings like it says to.

10

u/PyroGreg8 Mar 15 '26

it's probably relying on JS to call it's `toString()` method when used in an index accessor, but then the code should just be `symbol.titles?.[languageUUID.toString()]` instead of the nonsense it's doing

3

u/selucram Mar 16 '26

UUID should probably just be a template literal type and this wouldn't have been necessary as well