Hi, I was trying to use the Extends types (see #36) and ran into some unexpected behavior with StrictExtends.
My understanding is strict extension should be a subset of normal extension. That is to say, there should be no cases where a type strict extends another type, but does not traditionally extend it. If that is not the case, I would greatly appreciate some explanation on what these edge cases are.
Example:
type A = (args: string) => 5;
type B = (args: string | number) => number;
type doesExtend = A extends B ? true : false;
// doesExtend = false
// A cannot extend B because the parameters are too strict
expectTypeOf<
Extends<A, B>
>().toEqualTypeOf<false>(); // Correct / expected
expectTypeOf<
StrictExtends<A, B>
>().toEqualTypeOf<true>(); // Incorrect / unexpected?
My understanding is that is caused by this line: https://github.com/mmkal/expect-type/blob/main/src/index.ts#L43C11
It spreads the params + return equally.
extends of methods is a bit counter intuitive.
In order for method A to extend B:
- A's return type must be "stricter" than B's (
ReturnType<A> extends ReturnType<B>)
- This is handled correctly (as far as I can tell)
- A's parameters must be "laxer" than B's (
Parameters<B> extends Parameters<A>)
- This is not handled correctly
Hi, I was trying to use the
Extendstypes (see #36) and ran into some unexpected behavior withStrictExtends.My understanding is strict extension should be a subset of normal extension. That is to say, there should be no cases where a type strict extends another type, but does not traditionally extend it. If that is not the case, I would greatly appreciate some explanation on what these edge cases are.
Example:
My understanding is that is caused by this line: https://github.com/mmkal/expect-type/blob/main/src/index.ts#L43C11
It spreads the params + return equally.
extendsof methods is a bit counter intuitive.In order for method A to extend B:
ReturnType<A> extends ReturnType<B>)Parameters<B> extends Parameters<A>)