Skip to content
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

raidboss: Fix ParseHelperType definitions #5369

Merged
merged 1 commit into from
Apr 27, 2023
Merged

raidboss: Fix ParseHelperType definitions #5369

merged 1 commit into from
Apr 27, 2023

Conversation

valarnin
Copy link
Collaborator

To quote Discord DMs:

valarnin: ... is it just me, or is the ParseHelperType in netregexes.ts just flat out incorrectly defined? I just have no clue how typescript allows it in its current state.
Consider:

type ParseHelperType<T extends LogDefinitionTypes> =
  & {
    [field in Extract<keyof NetFieldsReverse[T], string>]?: string;
  }
  & { capture?: boolean };

type EmptyType = ParseHelperType<'Ability'>;

type ParseHelperTypeFixed<T extends LogDefinitionTypes> =
  & {
    [field in keyof NetFields[T]]?: string | string[];
  }
  & { capture?: boolean };

type CorrectType = ParseHelperTypeFixed<'Ability'>;

image
image

valarnin: (in fact, Extract<keyof NetFieldsReverse[T], string> evaluates to never because all keys of a given NetFieldsReverse type entry are numerical and therefore can never be assigned to string)

@quisquous
Copy link
Owner

How did this even work??

@quisquous quisquous merged commit 27ce3e0 into quisquous:main Apr 27, 2023
@valarnin
Copy link
Collaborator Author

How did this even work??

At a guess, the narrowing to never made typescript shrug and say "they probably know what they're doing", but honestly I have no clue. Or maybe it's because the parent types are pulled from a .d.ts file which is evaluated/scoped differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants