Skip to content

Commit

Permalink
fix for TS 5.4 (fix #35)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Mar 12, 2024
1 parent 6857d4a commit ed964d1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fixed for TypeScript 5.4. (Fix [#35](https://github.com/g-plane/typed-query-selector/issues/35))

## v2.11.0

- Added `.js` extension in import statements.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"fmt": "prettier --write *.ts"
},
"devDependencies": {
"@gplane/tsconfig": "^6.0.0",
"@gplane/tsconfig": "^6.1.0",
"@type-challenges/utils": "^0.1.1",
"prettier": "^3.0.3",
"typescript": "^5.1.3"
"typescript": "^5.4.2"
}
}
8 changes: 6 additions & 2 deletions parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ type PreprocessUnchecked<I> = I extends `${infer L}\\${Quotes}${infer R}` // rem

/** Parse `:is()` and `:where()` */
type ExpandFunctions<I> = I extends `${infer L}:is(${infer Args})${infer R}`
? ExpandFunctions<`${L}&${Split<Trim<Args>>}${R}`>
? Split<Trim<Args>> extends string
? ExpandFunctions<`${L}&${Split<Trim<Args>>}${R}`>
: unknown
: I extends `${infer L}:where(${infer Args})${infer R}`
? ExpandFunctions<`${L}&${Split<Trim<Args>>}${R}`>
? Split<Trim<Args>> extends string
? ExpandFunctions<`${L}&${Split<Trim<Args>>}${R}`>
: unknown
: I extends `${infer L}:${infer Pseudo}(${string})${infer R}`
? IsIdentifier<Pseudo> extends true
? ExpandFunctions<`${L}${R}`>
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shim.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare global {

querySelectorAll<S extends string>(
selector: S,
): NodeListOf<ParseSelector<S>>
): NodeListOf<ParseSelector<S> extends Node ? ParseSelector<S> : Node>

This comment has been minimized.

Copy link
@stof

stof Mar 12, 2024

@g-plane this change looks suspicious to me. Shouldn't ParseSelector always use its Fallback type instead of returning unknown ?

right now, other consumers of ParseSelector (which is a public API of this library) has do deal with unknown on their own. See fregante/delegate-it#50

This comment has been minimized.

Copy link
@g-plane

g-plane Mar 13, 2024

Author Owner

Oh, it should be Element here, not Node. I will fix it later.

This comment has been minimized.

Copy link
@stof

stof Mar 13, 2024

to me, the main point is that this should be fixed in the ParseSelector type, not in its usage in querySelectorAll

This comment has been minimized.

Copy link
@g-plane

g-plane Mar 13, 2024

Author Owner

ParseSelector has already handled for unknown type, and you can try by yourself. For more discussions, you can open new issue, not here.

}

interface Element {
Expand Down

0 comments on commit ed964d1

Please sign in to comment.