Following code has type errors with TypeScript 5.1.3:
import {
between,
char,
regex,
sepBy,
sequenceOf,
whitespace
} from "arcsecond";
const word = regex(/^\w+/);
const quotedString = between(char('"'))(char('"'))(regex(/^[^"]+/));
const attribute = sequenceOf([word, char("="), quotedString]).map(
([name, _, value]): [string, string] => [name, value]
);
const attributeList = sepBy(whitespace)(attribute).map(
(values): [string, string][] => values
);
export const parse = (input: string) => attributeList.run(input);
❯ pnpm build
> arcsecond-repro@0.1.0 build [REDACTED]/arcsecond-repro
> tsc -p .
src/parser.ts:15:52 - error TS2322: Type 'unknown' is not assignable to type 'string'.
15 ([name, _, value]): [string, string] => [name, value]
~~~~~
src/parser.ts:19:37 - error TS2322: Type 'unknown[]' is not assignable to type '[string, string][]'.
Type 'unknown' is not assignable to type '[string, string]'.
19 (values): [string, string][] => values
~~~~~~
Found 2 errors in the same file, starting at: src/parser.ts:15
ELIFECYCLE Command failed with exit code 2.
I would expect:
quotedString to contain type string, but TypeScript detects it as unknown.
- Generally: I would expect
between(_)(_)(T) to have type T instead of unknown.
attributeList to contain type [string, string][], but TypeScript detects it as unknown[].
- Generally: I would expect
sepBy(_)(T) to have type T[] instead of unknown[].
Please find a complete example in https://github.com/devurandom/arcsecond-issue-109-repro.
Following code has type errors with TypeScript 5.1.3:
I would expect:
quotedStringto contain typestring, but TypeScript detects it asunknown.between(_)(_)(T)to have typeTinstead ofunknown.attributeListto 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.