Incorrect types for MediaFeature

Open Beginner friendly
#249 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript
Domain
tooling

Research direction

Start with the MediaFeature definition in dist/node-types-mntWKkN-.d.ts and compare its child-related types with the runtime behavior described for min-width:0\0. The work is done when MediaFeature exposes the specified WithChildren union and its value property is narrowed to Identifier, Number, Dimension, or null.

Written by the indexing model from the issue text.

Description

bug

MediaFeature type is missing WithChildren

File: dist/node-types-mntWKkN-.d.ts

Problem

MediaFeature can have children beyond the .value node at runtime, but the type does not extend WithChildren. This makes node.has_children and for (const child of node) TypeScript errors even though they work correctly.

A concrete example is the CSS hack min-width:0\0. The parser emits a MediaFeature with two children: a Number node (0) exposed via .value, and a sibling Identifier node (\0) only reachable by iterating children.

Current definition
type MediaFeature = CSSNode & {
  readonly type: typeof MEDIA_FEATURE;
  readonly type_name: 'Feature';
  readonly property: string;
  readonly value: CSSNode | null;
  clone(options?: CloneOptions): ToPlain<MediaFeature>;
};

Expected definition

type MediaFeature = CSSNode & WithChildren<Identifier | Number | Dimension> & {
  readonly type: typeof MEDIA_FEATURE;
  readonly type_name: 'Feature';
  readonly property: string;
  readonly value: Identifier | Number | Dimension | null;
  clone(options?: CloneOptions): ToPlain<MediaFeature>;
};

Changes

  1. Add WithChildren<Identifier | Number | Dimension> — boolean features have no children; plain features have one child matching the value; the 0\0 hack produces two children.
  2. Narrow value: CSSNode | null → value: Identifier | Number | Dimension | null to match the actual child union.
Dominant language
CSS
Stars
4
Forks
0
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from projectwallace/css-parser

All issues in projectwallace/css-parser

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.