Hi

Am 2025-03-25 21:42, schrieb Rowan Tommins [IMSoP]:
And I've seen plenty of junior devs struggle with simple things like the difference between "nullable" and "optional", so I worry that making the type system too rich will lose PHP its reputation as an approachable language.


It's possible I'd react less strongly if a keyword was chosen that made more sense in context, although I'm not sure what that would be.

FWIW: There is precedent for “never” as a parameter type in TypeScript. In fact, the Comparable example I gave also works in TypeScript in an unmodified fashion:

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgMIHsC2AHOU4BGANigN4BQyVyCWuUEAKugBTpgAW0AXMiBADdoASl4gArpgLRyAX3LkEROAGcVyALIBPAHKTpUZMBwlMEcOow48hEsgrUadPE1bsuUXtr1SRY-dD2lI7UwDDIbJyBADzInMAqwkEhKcgMYOJQIMgAtACMwSmyyBBEKihhEe6BAHxxHAlJDqmO6ZnZBS3FpeXJLdRtWcgADIUh8o7y8uQw4iAIYMDo2TDorAi8VvS2EAA0yAAmm874xBBNY7QgKugkAHRE6ADmLAh3tNYMzCwHyKp8ghEwjkQA

The `compareTo()` method is indeed not callable OOTB and I need to tell the compiler that I know what I'm doing by the `as never` assertion, but it still guarantees me that the return value is a number.

I also expect folks to rarely encounter `never` as a parameter type in practice since generic interfaces are comparatively rare, but in the cases where you have a generic interface, `never` feels more useful to have than not having it.

Best regards
Tim Düsterhus

Reply via email to