Skip to content

Incorrect types for MediaFeature #249

Description

@bartveneman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions