Skip to content

Document noUncheckedSideEffectImports fixes for CSS packages - #3694

Open
Martin Ferret (MartinFerret) wants to merge 2 commits into
microsoft:v2from
MartinFerret:docs/no-unchecked-side-effect-imports-libraries
Open

Martin Ferret (MartinFerret) wants to merge 2 commits into
microsoft:v2from
MartinFerret:docs/no-unchecked-side-effect-imports-libraries

Conversation

@MartinFerret

Copy link
Copy Markdown

Fixes #3607

Since TypeScript 6.0, noUncheckedSideEffectImports is on by default, so import "library-name/css" fails with TS2882 when the subpath doesn't end in .css and has no declaration file. A "*.css" wildcard declaration doesn't help, since it doesn't match the specifier.

This PR updates the option's reference page:

  • Updates the example error message to the current TS2882 text.
  • Adds a section for library authors: ship a .d.css.ts file next to the stylesheet (users need allowArbitraryExtensions, otherwise TS6263), add a "types" condition in "exports" (no user setting needed), or expose a subpath ending in .css.
  • Adds two user-side options: declare the specifier in a global .d.ts, or set the option to false when a bundler already validates CSS imports.

The .d.css.ts approach follows the discussion in microsoft/TypeScript#62674.

The paragraph about the default behavior is left as is, since #3563 already updates it. The two PRs touch separate lines and merge without conflict in either order.

Every example was checked with TypeScript 6.0.3 and 7.0.2, with moduleResolution set to bundler and nodenext.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRITICAL: description on noUncheckedSideEffectImports has no guide for CSS npm library authors to have users avoid TS2882 when import css globally

1 participant