Live data from Hacker News

A complete guide to TypeScript’s 'never' type

zhenghao.io

61–64 of 64 posts

Re: A complete guide to TypeScript’s 'never' type

#61
post #18

What programmer hasn't at some point in their career written code like this: throw new Error(`Unexpected value: ${value}. This should never happen!`); ...and then had a user submit a bug report containing that very message. The `never` type is a nice way to model those scenarios and hopefully avoid such an error ever being seen by the user. // Compile error unless we've ruled out // `value` at the type level assertNe…

The first one is a very useful error as a user though. It tells me the unexpected value isn't my fault and I should go report a bug.

The interesting thing here is you can still get the error and display the message! Just that you _might_ be able to catch issues beforehand as well, and avoid even getting to that kind of code.

Typescript's practicality here does let you walk and chew bubblegum. This sort of stuff is super practical for UI development, because ultimately at the interfaces with servers you're likely to make some assumptions about incoming data, and so you'll have that fundamental cast in your code from any to Foo, and this sort of error will be reportable.

Re: A complete guide to TypeScript’s 'never' type

#62

Earlier quoted context omitted.

> But "poor grammar" specifically seeks to attribute a negative connotation to the utterance. It says suggest that people who construct such utterances are, somehow, uneducated, or else are outsiders. It says that they've done something that is objectively (not subjectively) incorrect or wrong. You're completely ignoring that people do make mistakes and get corrected. There is nothing in the post you originally repli…

> There is nothing in the post you originally replied to implying that anyone is uneducated or an outsider That's literally what the "poor" in "poor grammar" is doing, though. The phrase itself suggests that the speaker is lesser-than simply by virtue of not speaking in the same way as the listener would. > If I accidentally type "Eat I bread", it's incorrect grammar even if there happens to be some dialect somewhere…

> That's literally what the "poor" in "poor grammar" is doing, though. The phrase itself suggests that the speaker is lesser-than simply by virtue of not speaking in the same way as the listener would.

No, the "poor grammar" is just meaning "grammar that is incorrect" - I assume you're claiming that the meaning involves the speaker being poor? If that's what you believe, then I doubt anyone will convince you otherwise.

> It is not "incorrect". It is different. It is marked, maybe, for many native English speakers. But these are distinct things from "incorrect".

Literally everyone in this thread is using "incorrect" and being understood by everyone, so I don't see that you have any ground for claiming that "incorrect" is incorrect.

And you're still entirely missing that some things can be mistakes.

Re: A complete guide to TypeScript’s 'never' type

#63
post #10
post #7

Earlier quoted context omitted.

Funnily enough, in Russian the double negative is completely normal and that is a normal way to express many negatives. It always triggers my brain when I have to say a double negative in Russian, "just do it, it's completely normal, don't worry about it..." (inner feeling-based monologue). https://www.russiantutoring.com/post/double-negation-in-russ...

Reminds me of a classic linguistics joke (I assume from a Tom Scott video given where I encounter linguistics the most): A professor is lecturing on linguistics: "In English a double negative has a positive meaning. However, in some languages—such as Russian—a double negative still has a negative meaning. There isn't, however, a language in which a double positive holds a negative meaning." A student in the back resp…

This reminds me of ruminations with a friend about the nuance of combined positive/negative affirmations. Eg “no yeah” used as an emphatic agreement in the positive, and “yeah no” an emphatic agreement in the negative.

Re: A complete guide to TypeScript’s 'never' type

#64
post #30

Earlier quoted context omitted.

Sorry, I should have provided context. This was French, not Spanish. (I've clarified it in the original comment.) If it had been Spanish, transcribing it would be easier. French mooshes a lot of things together, so that "es" and "aies" are both pronounced "eh".

Note that they are two different verbs (to be and to have, respectively), so the context should have made it clear which one you should use.

I don’t know much French at all but I do know my way around English in really silly ways, and it’s amusing to me to superimpose this distinction on an English language context. Because they’re two different verbs which we use in conjunction for one existential verb, which barely exists without recruiting other verbs. Having had this state of amusement, I will have left these thoughts for your future amusement if you’ll have them too.
Post reply on HN