Skip to content

Instantly share code, notes, and snippets.

@felher
Created May 10, 2019 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felher/b202b6ccead15d3d2cc7803ed68e5f59 to your computer and use it in GitHub Desktop.
Save felher/b202b6ccead15d3d2cc7803ed68e5f59 to your computer and use it in GitHub Desktop.
function linePairContainerParser():P.Parser<M.FormteilContainer>{
return P.regexp(/[0-9]+/).map(num => (
{
"kind": M.ContainerKind.FormteilContainer,
uuid: UUID(),
children: []
}));
}
// this fails with:
//ERROR in src/app/types/parser.ts(92,3): error TS2322: Type 'Parser<{ "kind": ContainerKind; uuid: string; children: never[]; data: { "kind": FormteilDataKind; number: string; }; }>' is not assignable to type 'Parser<FormteilContainer>'.
// Type '{ "kind": ContainerKind; uuid: string; children: never[]; data: { "kind": FormteilDataKind; number: string; }; }' is not assignable to type 'FormteilContainer'.
// Types of property '"kind"' are incompatible.
// Type 'ContainerKind' is not assignable to type 'ContainerKind.FormteilContainer
//
// while this works just fine:
function linePairContainerParser():P.Parser<M.FormteilContainer>{
const k: M.ContainerKind.FormteilContainer = M.ContainerKind.FormteilContainer;
return P.regexp(/[0-9]+/).map(num => (
{
"kind": k,
uuid: UUID(),
children: []
}));
}
// ContainerKind looks like this:
export enum ContainerKind {
FormteilContainer = "FormteilContainer",
MiscContainer = "MiscContainer",
ParatextContainer = "ParatextContainer",
RootContainer = "RootContainer",
ZeileContainer = "ZeileContainer",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment