Skip to content

Declaration.important getter type excludes its documented undefined value #2180

Closed

Description

@CaliLuke

Declaration.important is declared as a boolean getter, but a parsed declaration without !important has undefined at runtime. The declaration documentation itself illustrates the undefined case.

Reproduced with PostCSS 8.5.31 and Node.js 26.

import postcss from "postcss";

postcss.parse("a { color: red }").walkDecls((declaration) => {
  const important: boolean = declaration.important;
  console.log(important.valueOf());
});

This type-checks with strict null checking, but throws Cannot read properties of undefined (reading 'valueOf') at runtime. Object.hasOwn(declaration, "important") is false for this input. With !important, the property is true.

Expected: the read type includes undefined, matching the existing documented runtime behavior. This would let strict TypeScript consumers handle the absent annotation correctly and prevent type-aware lint rules from incorrectly treating boolean normalization as redundant. No runtime behavior change is necessary.

Activity

  1. ai commented on Oct 30, 2026

    @ai
    Member

    Please, send PR

  2. added a commit that references this issue on Oct 31, 2026
    2faedf9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions