4 ms·
do you need readonly with never?
by nsonha 3y ago
do you need readonly with never?
- samtheprogram 3y agoYes, otherwise consumers could try reading the property (that doesn’t exist).
- nsonha 3y agohow would readonly fixes consumers reading the property?
- whilenot-dev 3y agoit doesn't. never prevents reading and readonly prevents (over)writing. GP just focused on the never-part of your question.
- nsonha 3y agonever means nothing can be assigned to it, so in that sense it's already readonly
- samtheprogram 3y agoCorrect, so the question should have been: is readonly necessary? I wouldn’t call myself an expert in TypeScript’s type system (although I use it daily), so I’m not sure about that one. I do know I would have omitted readonly if I did this myself, but perhaps by mistake.