-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
between
and sepBy
return unknown
type
#109
Comments
unknown
typebetween
and sepBy
return unknown
type
Hey @devurandom, const f = (a: unknown) => (b: unknown) => (c: string): [typeof a, typeof b, typeof c] => {
return [a, b, c];
}
const g = f(1)(true)("hello"); // -> const g: [unknown, unknown, string] A workaround for this is to use |
|
Could you explain this a bit more, please? The return type of What I have with const f = (a: unknown) => (b: unknown) => (c: string): [typeof a, typeof b, typeof c] => {
return [a, b, c];
}
const g = f(1)(true)("hello"); // -> const g: [unknown, unknown, unknown] //<< The third invocation / curry argument has the wrong type. And confusingly the type seems semi-correct, getting the "array aspect" correctly: const f = (a: unknown) => (b: unknown) => (c: string[]): [typeof a, typeof b, typeof c] => {
return [a, b, c];
}
const g = f(1)(true)(["hello","world"]); // -> const g: [unknown, unknown, unknown[]] //<< TypeScript noticed the third invocation returns an array, but it got the type of the elements wrong. |
What I did as a temporary countermeasure: import {
between as _between,
Parser,
sepBy as _sepBy,
} from "arcsecond";
const between = <L, R, T>(
left: Parser<L>,
right: Parser<R>,
value: Parser<T>
) => _between(left)(right)(value) as Parser<T>;
const sepBy = <S, T, E, D>(sep: Parser<S, E, D>, value: Parser<T, E, D>) =>
_sepBy(sep)(value) as Parser<T[], E, D>; A bit surprising was that const between = <L, R, T, E, D>(
left: Parser<L, E, D>,
right: Parser<R, E, D>,
value: Parser<T, E, D>
) => _between(left)(right)(value) as Parser<T, E, D>; because TypeScript would report an error:
probably because const between =
<L, T, R>(leftParser: Parser<L>) =>
(rightParser: Parser<R>) =>
(parser: Parser<T>): Parser<T> =>
sequenceOf([leftParser, parser, rightParser]).map(([_l, x, _r]) => x); and not: const _between =
<L, T, R, E, D>(leftParser: Parser<L, E, D>) =>
(rightParser: Parser<R, E, D>) =>
(parser: Parser<T, E, D>): Parser<T, E, D> =>
sequenceOf([leftParser, parser, rightParser]).map(([_l, x, _r]) => x); which in turn is an effect of
|
Following code has type errors with TypeScript 5.1.3:
I would expect:
quotedString
to contain typestring
, but TypeScript detects it asunknown
.between(_)(_)(T)
to have typeT
instead ofunknown
.attributeList
to contain type[string, string][]
, but TypeScript detects it asunknown[]
.sepBy(_)(T)
to have typeT[]
instead ofunknown[]
.Please find a complete example in https://github.com/devurandom/arcsecond-issue-109-repro.
The text was updated successfully, but these errors were encountered: