Fix Could not find a declaration file for module 'css-tree' type error#8452
Conversation
🦋 Changeset detectedLatest commit: fe797b4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I'm wondering if a library like Stylelint should provide 3rd-party type packages (i.e. |
|
Well this discussion pops up everywhere :) In my opinion ... A lot of npm packages already bring bundled type information, for example postcss (which Stylelint depends on) installs all its type information - although not all users need them. So css-tree and @types/css-tree should be seen as one "logical package" that should be installed by Stylelint if it depends on it publically, to allow seemless integration in TS based projects. |
|
If I'm still concerned whether we should provide all Lines 179 to 192 in a335c8b And, for type-checking on Stylelint development, we have applied a patch to |
|
Maybe better to write specific types for the parts of the |
|
Ideally, it'd be best that @ryo-manba recently committed to
In short, I think we'd all be happy if we could resolve the issue upstream. 😃 |
|
Sorry, I should have addressed this when I added the type definitions. Since we are only adding the By the way, eslint/css includes its own type definitions as dependencies (Reference: eslint/css#44). |
|
@romainmenke Not 100% sure, but do you think it's challenging to add types upstream (on the I'm worrying if users might be confused about whether Stylelint would provide such |
I think this would be indeed challenging. I did however misunderstand why we have a public dependency on I don't think we want to have our own copy of this type. With that in mind I don't really see a better option than moving Maybe we could create some more specialized utilities on top of the |
Could not find a declaration file for module 'css-tree' type error
Try the Instant Preview in Online DemoInstall the Instant Preview to Your Local |
|
@romainmenke Thank you for the explanation. Now I understand the difficulties of adding types to To make this problem easier to see, I created a small reproduction gist based on the #8435 report: Please run the following commands for the reproduction: git clone https://gist.github.com/ybiquitous/b7746ba3581e1c285628fb51c244cb1b test
cd test
npm i && npx tscThen, the output should be: The error is caused by our dependency on the stylelint/types/stylelint/index.d.ts Line 4 in 1ec1253 So, I agree with publishing this PR, and I'm sorry for taking time. 🙇🏼 But, we will have to be more careful so not to publish our patched types in the future: stylelint/patches/@types+css-tree+2.3.10.patch Lines 1 to 18 in a335c8b Luckily, the |
ybiquitous
left a comment
There was a problem hiding this comment.
Thank you for the PR, LGTM 👍🏼
|
[note] This is not a blocker. Please let me just express my opinion. We should probably have published a Stylelint own wrapper type for the CSSTree stylelint/docs/developer-guide/rules.md Line 310 in 1ec1253 stylelint/types/stylelint/index.d.ts Line 374 in 1ec1253 From a long-term perspective of Stylelint public API, it does not seem wise for me to depend on a specific third party. If we'd like to switch to an alternative, it would be more difficult since the community already depended on CSSTree. Because of my recent busy days, I may lack an understanding of the background around the |
|
I agree and it is unfortunate that we overlooked this when implementing the language options. But I think it is not too late to change this, even when it technically is a breaking change. Chances are very slim that any 3rd party rule already depends on this. We could first make this an internal type, remove the docs for Something like: /**
* A rule context.
*/
export type RuleContext = {
configurationComment?: string | undefined;
fix?: boolean | undefined;
newline?: string | undefined;
/** @internal */
lexer?: unknown | undefined;
};And then cast to /** @import { Lexer } from 'css-tree' */
/**
* @param {import('stylelint').RuleContext} context
* @returns {Lexer}
*/
export default function getLexer(context) {
if (!context?.lexer) {
throw new Error('Expected a "lexer" object');
}
if (!('matchAtrulePrelude' in Object(context?.lexer))) {
throw new Error('Expected lexer" to be a css-tree lexer');
}
const lexer = /** @type Lexer */ (context.lexer);
return lexer;
} |
|
I see. Honestly, I'm not sure about the impact on the user land (e.g., plugins), but this might be the last opportunity to reconsider the |
Reconsidering the published context.lexer property.
|
It sounds like a good way forward, and it's not too late to make this change. @danielrentz Can you please update the PR to:
I can make time to do a release once it's done. |
|
@jeddy3 @romainmenke done. |
|
We should revert the dependency change, right? |
|
@ybiquitous I did that in my 2nd commit |
ybiquitous
left a comment
There was a problem hiding this comment.
Oh I missed the revert, sorry. LGTM except for the next version topic, minor or patch.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "stylelint": patch | |||
There was a problem hiding this comment.
Should this PR be considered as minor instead of patch because it makes a change of the part of the public API?
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
@danielrentz Thanks for making the changes. LGTM.
@ybiquitous Thanks for looking over it.
I'll merge and release this afternoon.
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.15.0 | 16.16.0 | ## [v16.16.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16160---2025-03-14) It adds support for computing `EditInfo` to 22 more rules and reverts a change that added `context.lexer` to our public API in the previous release. - Added: `at-rule-empty-line-before` support for computing `EditInfo` ([#8425](stylelint/stylelint#8425)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `at-rule-no-deprecated` support for computing `EditInfo` ([#8426](stylelint/stylelint#8426)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `at-rule-no-vendor-prefix` support for computing `EditInfo` ([#8427](stylelint/stylelint#8427)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `color-function-notation` support for computing `EditInfo` ([#8437](stylelint/stylelint#8437)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `declaration-empty-line-before` support for computing `EditInfo` ([#8443](stylelint/stylelint#8443)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `declaration-property-value-keyword-no-deprecated` support for computing `EditInfo`. ([#8439](stylelint/stylelint#8439)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `font-family-name-quotes` support for computing `EditInfo` ([#8419](stylelint/stylelint#8419)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `font-weight-notation` support for computing `EditInfo` ([#8420](stylelint/stylelint#8420)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `function-calc-no-unspaced-operator` support for computing `EditInfo` ([#8440](stylelint/stylelint#8440)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `function-name-case` support for support for computing `EditInfo`." ([#8442](stylelint/stylelint#8442)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `hue-degree-notation` support for computing `EditInfo` ([#8444](stylelint/stylelint#8444)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `import-notation` support for computing `EditInfo`. ([#8445](stylelint/stylelint#8445)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `keyframe-selector-notation` support for computing `EditInfo` ([#8457](stylelint/stylelint#8457)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `length-zero-no-unit` support for computing `EditInfo` ([#8459](stylelint/stylelint#8459)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `lightness-notation` support for computing `EditInfo` ([#8458](stylelint/stylelint#8458)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `media-feature-name-no-vendor-prefix` support for computing `EditInfo` ([#8456](stylelint/stylelint#8456)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `media-feature-range-notation` support for computing `EditInfo` ([#8455](stylelint/stylelint#8455)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `property-no-vendor-prefix` support for computing `EditInfo` ([#8461](stylelint/stylelint#8461)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `rule-empty-line-before` support for computing `EditInfo` ([#8460](stylelint/stylelint#8460)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-no-vendor-prefix` support for `EditInfo` ([#8462](stylelint/stylelint#8462)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-not-notation` support for computing `EditInfo` ([#8463](stylelint/stylelint#8463)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-pseudo-element-colon-notation` support for `EditInfo` ([#8464](stylelint/stylelint#8464)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-type-case` support for computing `EditInfo` ([#8467](stylelint/stylelint#8467)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `shorthand-property-no-redundant-values` support for computing `EditInfo` ([#8466](stylelint/stylelint#8466)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `value-keyword-case` support for computing `EditInfo` ([#8469](stylelint/stylelint#8469)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `value-no-vendor-prefix` support for computing `EditInfo` ([#8470](stylelint/stylelint#8470)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Fixed: `Could not find a declaration file for module 'css-tree'` type error ([#8452](stylelint/stylelint#8452)) ([@danielrentz](https://github.com/danielrentz)).
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.15.0 | 16.16.0 | ## [v16.16.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16160---2025-03-14) It adds support for computing `EditInfo` to 22 more rules and reverts a change that added `context.lexer` to our public API in the previous release. - Added: `at-rule-empty-line-before` support for computing `EditInfo` ([#8425](stylelint/stylelint#8425)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `at-rule-no-deprecated` support for computing `EditInfo` ([#8426](stylelint/stylelint#8426)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `at-rule-no-vendor-prefix` support for computing `EditInfo` ([#8427](stylelint/stylelint#8427)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `color-function-notation` support for computing `EditInfo` ([#8437](stylelint/stylelint#8437)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `declaration-empty-line-before` support for computing `EditInfo` ([#8443](stylelint/stylelint#8443)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `declaration-property-value-keyword-no-deprecated` support for computing `EditInfo`. ([#8439](stylelint/stylelint#8439)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `font-family-name-quotes` support for computing `EditInfo` ([#8419](stylelint/stylelint#8419)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `font-weight-notation` support for computing `EditInfo` ([#8420](stylelint/stylelint#8420)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `function-calc-no-unspaced-operator` support for computing `EditInfo` ([#8440](stylelint/stylelint#8440)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `function-name-case` support for support for computing `EditInfo`." ([#8442](stylelint/stylelint#8442)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `hue-degree-notation` support for computing `EditInfo` ([#8444](stylelint/stylelint#8444)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `import-notation` support for computing `EditInfo`. ([#8445](stylelint/stylelint#8445)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `keyframe-selector-notation` support for computing `EditInfo` ([#8457](stylelint/stylelint#8457)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `length-zero-no-unit` support for computing `EditInfo` ([#8459](stylelint/stylelint#8459)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `lightness-notation` support for computing `EditInfo` ([#8458](stylelint/stylelint#8458)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `media-feature-name-no-vendor-prefix` support for computing `EditInfo` ([#8456](stylelint/stylelint#8456)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `media-feature-range-notation` support for computing `EditInfo` ([#8455](stylelint/stylelint#8455)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `property-no-vendor-prefix` support for computing `EditInfo` ([#8461](stylelint/stylelint#8461)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `rule-empty-line-before` support for computing `EditInfo` ([#8460](stylelint/stylelint#8460)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-no-vendor-prefix` support for `EditInfo` ([#8462](stylelint/stylelint#8462)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-not-notation` support for computing `EditInfo` ([#8463](stylelint/stylelint#8463)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-pseudo-element-colon-notation` support for `EditInfo` ([#8464](stylelint/stylelint#8464)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-type-case` support for computing `EditInfo` ([#8467](stylelint/stylelint#8467)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `shorthand-property-no-redundant-values` support for computing `EditInfo` ([#8466](stylelint/stylelint#8466)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `value-keyword-case` support for computing `EditInfo` ([#8469](stylelint/stylelint#8469)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `value-no-vendor-prefix` support for computing `EditInfo` ([#8470](stylelint/stylelint#8470)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Fixed: `Could not find a declaration file for module 'css-tree'` type error ([#8452](stylelint/stylelint#8452)) ([@danielrentz](https://github.com/danielrentz)).
Closes #8435
The
types.d.tspublished by stylelint imports from "css-tree", so their types definitions (from@types/css-tree) should be installed as well.