As someone new to TypeScript, I have a question regarding my code. I am converting TypeScript into JavaScript to run in an environment where the window
object has additional functions that I have declared on the TypeScript side like this:
interface Window {
getID() : number
setID(id: number) : void
}
While this setup works as intended, I want to restrict certain operations on these IDs within my TypeScript code. Specifically, I do not want to allow actions such as adding them, incrementing them, or converting them into strings. Ideally, the only permissible operation should be setID(getID())
.
I believe what I need is a custom bottom type that behaves similarly to never
, but with restrictions beyond those imposed by never
. Is it possible to create such a type? Alternatively, would using never
be the closest approximation?
Edit: Upon further research, I discovered a proposal for nomial type support, which aligns perfectly with my requirements.