Comments (8)
You cannot benefit from --noUncheckedSideEffectImports
while using ambient module declaration.
declare module '*.css'
in your globals.d.ts
is the way to have TS assume every module specifier that ends with .css
is valid.
Mention to .css
files in the 5.6 release announcement is all about use cases not covered by --noUncheckedSideEffectImports
.
If you want to utilize --noUncheckedSideEffectImports
for CSS imports, you need to stop using ambient module declarations and instead use a solution like this that generates .d.ts
files next to each of your .css
files
from typescript.
I can't reproduce what you're reporting there.
D:\Throwaway\nusi>tsc
a.ts:1:8 - error TS2307: Cannot find module 'foo.css' or its corresponding type declarations.
1 import "foo.css";
~~~~~~~~~
Maybe you have a @types
library that also does declare module "*.css"
?
from typescript.
You cannot benefit from
--noUncheckedSideEffectImports
while using ambient module declaration.
declare module '*.css'
in yourglobals.d.ts
is the way to have TS assume every module specifier that ends with.css
is valid.Mention to
.css
files in the 5.6 release announcement is all about use cases not covered by--noUncheckedSideEffectImports
.If you want to utilize
--noUncheckedSideEffectImports
for CSS imports, you need to stop using ambient module declarations and instead use a solution like this that generates.d.ts
files next to each of your.css
files
Thank you for your response and for the alternative options you gave that may make things work.
However though, it is either a confusing wording in release announcement, or it is indeed an issue.
The release announcement for this section literally reads like this:
- Some people may have their builders configured to directly import
.css
files this masks potential typos on side effect imports
Thatβs why TypeScript 5.6 introduces a new compiler option
A bit below we can read this:
When enabling this option, some working code may now receive an error, like in the CSS example above.
To work around this, users who want to just write side effect imports for assets might be better served by writing whatβs called an ambient module declaration with a wildcard specifier
Not a word about the flag not supporting errors for .css
or any other side effects import modules.
from typescript.
Another thing to add to the conversation here is the name of the flag (noUncheckedSideEffectImports
) is pretty general, which makes me think it covers all the side effect imports, not just js modules.
from typescript.
I don't really understand what you're proposing happen here. There still needs to be a mechanism to tell TypeScript about modules which will successfully resolve but aren't on disk. That mechanism is declare module
, and you used declare module
. TypeScript correctly interpreted your description of the world (even if it's not what you meant to describe).
from typescript.
I don't really understand what you're proposing happen here. There still needs to be a mechanism to tell TypeScript about modules which will successfully resolve but aren't on disk. That mechanism is
declare module
, and you useddeclare module
. TypeScript correctly interpreted your description of the world (even if it's not what you meant to describe).
Thanks @RyanCavanaugh for joining the discussion.
Ok, it'll put it in other words. My recent testing has shown that the following side effect imports (and their variations) are well-treated by typescript and it throws an expected error (with the compiler flag on, of course):
import 'does-not-exit'
import 'does-not-exit.does-not-exit''
import 'does-not-exit.1234567'
import '1234567.1234567'
etc.
However, once there is .css
in the file name (or anything css-related, like less
, sass
etc) ts ignores such imports, whether there is declare module '*.css' {}
or not.
import 'does-not-exit.css'
I wonder why ts reacts to the .css
in the name this way?
Having .css
in the name of the file may not necessary mean it is a css
file. Imagine a rough use case when one has a js
module file that exports some stuff that generates some CSS (the reason to have css
in the name). Something like *.css.js
. It'll be ignored when imported incorrectly even though its a js module, unless the .js
extension is specified explicitly.
from typescript.
Good point @RyanCavanaugh , I think I know what's going on there. Even though the environment for the reproduction I gave was clean, it was, apparently, built by Vite. And Vite does this:
And a lot more.
I didn't know or expect that, and now everything makes total sense.
So, thank you @uhyo and @RyanCavanaugh for your input, and I'm sorry for the false alarm. Closing this one.
from typescript.
Not an issue. Works as expected.
from typescript.
Related Issues (20)
- CommonJS module output broken after updating from 5.5.4 to 5.6.2 HOT 7
- Type inference when using `extend` in a generic is not consistent HOT 3
- Check when a function that uses `this` is referenced without binding it HOT 2
- Built-in URL is not compatible with `@types/node` URL
- [suggest] constructor init delegation with "strictPropertyInitialization" HOT 2
- Potential memory leak or dead recursive during auto completion HOT 2
- Incorrect type deducted for accumulator in reduce HOT 2
- moduleResolution: 'bundler' with subpath import seem to not support directory module and extensionless import HOT 4
- Source mappings are missing for serialized properties
- Missing overload method on union types HOT 7
- JSDoc `@import` of "tslib" fails under `--moduleResolution bundler`
- Interface that extends another no longer constrains types like the original HOT 1
- Proposal: Allow isolated declarations to infer results of constructor calls HOT 10
- Property 'difference' does not exist on type 'Set' HOT 3
- Type narrowing of condition leads to unexpected error for assignment HOT 3
- Increase the distinction between class and interface properties when defining a class or interface
- Add adaptation to class and interface property prompts HOT 1
- Weird behavior with recursive generic types HOT 2
- Array of unions changed to union of arrays in conditional type HOT 4
- tsserver requires `npm` to be installed on `neovim` trough `mason` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.