Just sharing my personal trick, which is a bit off topic and hacky.
I usually prefer to handle such edge cases within the objet literal itself, by providing a default key.
Then I basically lie to the TypeScript compiler by omitting the extra default key in my type definitions.
interfaceStatus{online:'Online',offline:'Offline',busy:'Busy',dnd:'Do Not Disturb',}functiongetDisplayedStatus(status:keyofStatus){conststatusDisplays={online:'Online',offline:'Offline',busy:'Busy',dnd:'Do Not Disturb',default:'Unknown'}returnstatusDisplays[status]||status.default}constdisplayedStatus=getDisplayedStatus(statusaskeyofStatus)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just sharing my personal trick, which is a bit off topic and hacky.
I usually prefer to handle such edge cases within the objet literal itself, by providing a
default
key.Then I basically lie to the TypeScript compiler by omitting the extra
default
key in my type definitions.