Closed ecyrbe closed 6 months ago
This allows to match exactly and also customize the predicate to match or pass a checker. So with this, you can match types only. So not just check if something extends a string, but check that something is actually a type string:
interface ExtendsTypeOf extends Fn { return: this["arg0"] extends this["arg1"] ? true: false; } interface IsArray extends Fn { return: this["arg0"] extends unknown[] ? true: false; } type TestTypes<T> = Match<T,[ Match.WithEqual<string, "string">, Match.WithEqual<number, "number">, Match.WithEqual<boolean, "boolean">, Match.WithEqual<null, "null">, Match.WithPredicate<ExtendsTypeOf, Record<string,unknown> , "object">, // same as `Match.With<Record<string, unknown>, "object">` Match.With<IsArray , "array">, // same as `Match.With<unknown[], "array">` Match.With<any, "not a json type"> ]>;
I'm not found of my naming here. suggestions are welcomed
This allows to match exactly and also customize the predicate to match or pass a checker.
So with this, you can match types only. So not just check if something extends a string, but check that something is actually a type string: