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

fix(puppeteer-core): avoid type instantiation errors #9370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 21 additions & 17 deletions packages/puppeteer-core/src/common/types.ts
Expand Up @@ -135,32 +135,36 @@ type BeginSubclassSelectorTokens = ['.', '#', '[', ':'];

type CombinatorTokens = [' ', '>', '+', '~', '|', '|'];

type Drop<Arr extends readonly unknown[], Remove> = Arr extends [
infer Head,
...infer Tail
]
type Drop<
Arr extends readonly unknown[],
Remove,
Acc extends unknown[] = []
> = Arr extends [infer Head, ...infer Tail]
? Head extends Remove
? Drop<Tail, Remove>
: [Head, ...Drop<Tail, Remove>]
: [];
: Drop<Tail, Remove, [...Acc, Head]>
: Acc;

type FlatmapSplitWithDelemiters<
Inputs extends readonly string[],
Delemiters extends readonly string[]
Delemiters extends readonly string[],
Acc extends string[] = []
> = Inputs extends [infer FirstInput, ...infer RestInputs]
? FirstInput extends string
? RestInputs extends readonly string[]
? [
...SplitWithDelemiters<FirstInput, Delemiters>,
...FlatmapSplitWithDelemiters<RestInputs, Delemiters>
]
: never
: never
: [];
? FlatmapSplitWithDelemiters<
RestInputs,
Delemiters,
[...Acc, ...SplitWithDelemiters<FirstInput, Delemiters>]
>
: Acc
: Acc
Comment on lines +160 to +161
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two branches are never taken.

: Acc;

type Split<
Input extends string,
Delemiter extends string
Delemiter extends string,
Acc extends string[] = []
> = Input extends `${infer Prefix}${Delemiter}${infer Suffix}`
? [Prefix, ...Split<Suffix, Delemiter>]
: [Input];
? Split<Suffix, Delemiter, [...Acc, Prefix]>
: [...Acc, Input];
12 changes: 12 additions & 0 deletions test-d/NodeFor.test-d.ts
Expand Up @@ -6,6 +6,18 @@ declare const nodeFor: <Selector extends string>(
) => NodeFor<Selector>;

{
{
expectType<HTMLTableRowElement>(
nodeFor(
'[data-testid="my-component"] div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div tbody tr'
)
);
expectNotType<Element>(
nodeFor(
'[data-testid="my-component"] div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div tbody tr'
)
);
}
{
expectType<HTMLAnchorElement>(nodeFor('a'));
expectNotType<Element>(nodeFor('a'));
Expand Down