You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This doesn't work. I want to infer types from arguments, but now arguments are typed based on generic types.
Second idea:
exportfunctionchoice<TToken,TOptions,TParserextendsParser<TToken,TOptions,TValue1>,TValue1=TParserextendsParser<TToken,TOptions,infer T> ? T : never>(
...ps: TParser[]): Parser<TToken,TOptions,TValue1>;
This fails on a call without arguments (and I skipped testing it for more than 1 argument).
Maybe it would be possible to fix, but then I come to realization that it is not clear how this should be written for the Matcher overload.
My next thought:
I have an array of functions. I can get return type of a function with ReturnType<> utility if needed. Then I would need some contraption to turn an array into a unity type.
If there is a solution - it might even work for Matcher overload. And the case of an empty array would be a step in reduction.
Will get back to this.
The text was updated successfully, but these errors were encountered:
exportfunctionchoice<TToken,TOptions,TParsersextendsParser<TToken,TOptions,unknown>[],TValue=TParsers[number]extendsParser<TToken,TOptions,infer T> ? T : never>(
...ps: TParsers): Parser<TToken,TOptions,TValue>;
Type tests are passing for any number of arguments.
But some previously working examples are now failing.
Overload 2 of 2, '(...ps: Parser<unknown, unknown, unknown>[]): Parser<unknown, unknown, unknown>', gave the following error.
Argument of type 'Parser<Token, unknown, number>' is not assignable to parameter of type 'Parser<unknown, unknown, unknown>'.
Types are lost somewhere in certain practical scenarios.
This gets into esoteric category again (#67) - can't ship it like this.
Is it possible for
choice(pa, pb, pc)
to infer a parser ofTA | TB | TC
as a result?Currently it requires a type hint - cast at least on of arguments to more common type.
First idea - change it like following:
This doesn't work. I want to infer types from arguments, but now arguments are typed based on generic types.
Second idea:
This fails on a call without arguments (and I skipped testing it for more than 1 argument).
Maybe it would be possible to fix, but then I come to realization that it is not clear how this should be written for the Matcher overload.
My next thought:
I have an array of functions. I can get return type of a function with
ReturnType<>
utility if needed. Then I would need some contraption to turn an array into a unity type.If there is a solution - it might even work for Matcher overload. And the case of an empty array would be a step in reduction.
Will get back to this.
The text was updated successfully, but these errors were encountered: