Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Spell `Selector` without the self-reference its base type holds

Đang mở
#348 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, typescript
Lĩnh vực
backend

Hướng nghiên cứu

Start by tracing the Selector and Container type declarations and the Node union, then reproduce the reported TS5115 with the consumer example under TypeScript 7.1 nightly. Compare the listed type spellings against the supported TypeScript versions and decide how selector children should be represented. Done means the chosen approach checks for consumers on the nightly without breaking the listed released versions.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Selector no longer checks on the TypeScript 7.1 nightlies, since the nightly of 2026-09-29.

$ npm i -D typescript@next
$ tsc --noEmit --strict --skipLibCheck app.ts
app.ts(9,20): error TS5115: Instantiations of the following types appear infinitely circular: 'Container', 'Diff'.

The error is reported where Selector is used, not in the declaration, so it depends on what the consumer does with the type rather than on the package alone.

The spelling is the workaround of #232: type Selector = _Selector<Selector> over interface _Selector<S> extends Container<string, Diff<Node, S>>. No released TypeScript is affected — 4.0.3, 4.9.5, 5.0.4, 5.9.3 and 7.0.2 all check it — and the nightlies of 2026-09-28 and earlier do too.

Here is what each spelling costs, measured with tsc --noEmit --strict on a consumer that narrows a selector's children by type and reads them:

spelling of Selector 4.0.3 5.9.3 7.0.2 7.1 nightly
_Selector<S> + type Selector = _Selector<Selector>, as shipped ok ok ok TS5115
interface Selector extends Container<string, Exclude<Node, Selector>> TS2310 TS2310 TS2310 ok
interface Selector extends Container<string, Diff<Node, Selector>> TS2310 TS2310 TS2310 ok
interface Selector extends Container<string, Diff<Node, NodeTypes["selector"]>> TS2310 TS2310 TS2310 ok
type SelectorChild = Diff<Node, Selector>, Selector extends Container<string, SelectorChild> TS2310 TS2310 TS2310 ok
interface Selector<S = Selector> extends Container<string, Diff<Node, S>> errors errors errors errors
interface Selector extends Container<string, Node> ok ok ok ok

A selector that says its children are the nodes that are not selectors has to name the node union in its own base type, and that union holds Selector — which is the cycle, whichever way it is spelled. Adding a default argument to _Selector changes nothing, since the alias still names itself.

So there seem to be three ways out, and I would rather ask than pick:

  • drop the exclusion, so a selector's children are Node[]. The parser never puts a selector inside a selector, but selector.nodes was the one place in the tree that said so.
  • declare nodes on Selector itself rather than through Container, if that keeps the base type free of the node union.
  • leave it, and let the consumers on the nightly carry a patch until 7.1 ships.

We hit this in stylelint-stylistic, which pins typescript@next; the workaround there is a patchedDependencies entry that would be glad to drop once any of the lands.

Ngôn ngữ chính
JavaScript
Star
216
Fork
81
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của postcss/postcss-selector-parser

Tất cả issue của postcss/postcss-selector-parser

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.