Live data from Hacker News

A complete guide to TypeScript’s 'never' type

zhenghao.io

11–20 of 64 posts

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

#11
post #7
post #6

Earlier quoted context omitted.

I have seen such double negative at many places, to represent strong negative. Don't know if it is some trend!

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...

The high-brow name for this syntactic gadget is “negative concord”[1], and Wikipedia lists plenty of languages that have it[2] (including several European ones and even Old English!).

[1] http://glottopedia.org/index.php/Negative_concord

[2] https://en.wikipedia.org/wiki/Double_negative

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

#12
post #8

tldr: A method that is typed as returning `never` either never returns (infinite while/for loop) or throws an error. And as return types can also be conditional, your given inputs may switch the return to `never`, allowing typescript to tell you that code following that line will never be executed.

This is only one use case for never. The article goes into a lot more than this. For example using never to create derived types is pretty common.

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

#13
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 is widely attributed to Sidney Morgenbesser (https://en.wikipedia.org/wiki/Sidney_Morgenbesser).

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

#14

> Since there’s no values in the set, never type can’t never (pun-intended) have any value That’s not a pun that’s just poor grammar. “never type can never (pun-intended) have any value” makes sense.

> That’s not a pun that’s just poor grammar.

There is no such thing as "poor grammar" --- it's a myth. Most of the grammatical "rules" we tend to be taught in primary and secondary school English courses were invented relatively recently, and they were created specifically for the purpose of establishing an arbitrary class distinction.

Now, there's something to be said about markedness [1]. If the majority of a specific group of speakers of a language find a particular utterance (phrase, sentence, pronunciation, etc) to stand out in a way that feels unnatural, then that utterance is called "marked". Clearly, "can't never" is marked in your perspective. (And, indeed, I also find it to be marked in my own dialect.)

However...

There do exist large groups of native English speakers for whom this utterance is not marked. In these groups, this is a regular way to emphasize a negative. So, in those groups, the utterance is unmarked.

So it is wrong to say that your notion of markedness is universal. Undoubtedly, there are utterances you would produce that members of other groups of native English speakers would find marked. (A simple example offhand: American English speakers find the British constructions of "go to hospital" or "to be on holiday" to be marked. Does that make these utterances ungrammatical universally? Absolutely not.)

Context is important. If you are writing, say, an academic paper that you want to publish at a particular venue, then you are expected to adhere to the grammatical conventions of that venue. But for general everyday speech? The rule is straightforward: if you understand the intent, then it is not incorrect. It might be marked for you, but that does not make it "wrong" or "bad" or "poor" universally.

[1] https://en.wikipedia.org/wiki/Markedness

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

#15

> Since there’s no values in the set, never type can’t never (pun-intended) have any value That’s not a pun that’s just poor grammar. “never type can never (pun-intended) have any value” makes sense.

> That’s not a pun that’s just poor grammar. There is no such thing as "poor grammar" --- it's a myth. Most of the grammatical "rules" we tend to be taught in primary and secondary school English courses were invented relatively recently, and they were created specifically for the purpose of establishing an arbitrary class distinction. Now, there's something to be said about markedness [1]. If the majority of a speci…

Any sources on poor grammar being a new thing? It's been taught in public/private schools in England for centuries, maybe even millennia.

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

#16
post #15

Earlier quoted context omitted.

> That’s not a pun that’s just poor grammar. There is no such thing as "poor grammar" --- it's a myth. Most of the grammatical "rules" we tend to be taught in primary and secondary school English courses were invented relatively recently, and they were created specifically for the purpose of establishing an arbitrary class distinction. Now, there's something to be said about markedness [1]. If the majority of a speci…

Any sources on poor grammar being a new thing? It's been taught in public/private schools in England for centuries, maybe even millennia.

Pedagogical history isn't a strong argument for something's truth, just its usefulness to someone. Theology was considered a key component of a higher education for centuries and is still taught for example.

People have always strongly believed, and taught, things about their own languages and languages in general. They're not all wrong necessarily. But linguistics over the last like 80 years has produced some models that have incredible predictive and explanatory power, and are incompatible with a view of an objective "correct" or "best" or "standard" form of a language.

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

#17

> Since there’s no values in the set, never type can’t never (pun-intended) have any value That’s not a pun that’s just poor grammar. “never type can never (pun-intended) have any value” makes sense.

> That’s not a pun that’s just poor grammar. There is no such thing as "poor grammar" --- it's a myth. Most of the grammatical "rules" we tend to be taught in primary and secondary school English courses were invented relatively recently, and they were created specifically for the purpose of establishing an arbitrary class distinction. Now, there's something to be said about markedness [1]. If the majority of a speci…

I'm sure there's some validity to this from an anthropological/linguistic standpoint (I'm a big fan of "sounds prescriptivist but ok").

But look at your own comment:

> Context is important. If you are writing, say, an academic paper that you want to publish at a particular venue, then you are expected to adhere to the grammatical conventions of that venue.

This is a technical blog post addressing a technical audience. In fact the sentence in question is explaining a technical concept. Therefore the (unwritten?) rules of technical writing apply.

So it's inappropriate here to give lection on linguistic relativism.

For the purposes of the article, its audience, and the particular sentence in question, this is poor grammar.

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

#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
    assertNever(value, new Error(`Unexpected value: ${value}.`));

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

#19

> Since there’s no values in the set, never type can’t never (pun-intended) have any value That’s not a pun that’s just poor grammar. “never type can never (pun-intended) have any value” makes sense.

Irregardless of your subjective opinion about grammar, you literally expressed the exact same thing. It’s either a pun in both or it’s a pun in neither.
Post reply on HN