-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write the .d.ts as declare module ${pathToFile}
#270
Comments
The suggestion also allows all of the types to be in a single file, instead of dozens of files. This surely also fixes the issue with the IDE being slow to update the types when tcm is run. Also, there could be a flag for the CLI to enforce wildcard imports instead of the default import. This is important for Parcel v2 due to its treeshaking. The output would be: declare module 'path/to/your/cssfile.css' {
export namespace styles {
const drawer: string;
const overlay: string;
// ... other classes
}
} |
Yes, or in multiple files but in a single dedicated directory like |
@stevenpetryk most of what you said is correct - except one little detail that actually makes a workaround possible.
You're right that relative paths don't work, but absolute paths do. Given that, consider a project like this: With tsconfig's path aliases, you can add an import alias for any folder, including the root folder. You could alias the {
// …
"compilerOptions": {
// …
"paths": {
"@styles/*": ["./src/styles/*"]
}
}
} Now we can do this (although you'd still get a // src/index.ts
import fooStyles from '@styles/foo.module.css`; Now, you can add a definition file anywhere in the project, like // global.d.ts
declare module "@styles/foo.module.css" {
const stylesheet: { hello: "world" }; // <- to be generated by TCM
export default stylesheet;
}
declare module "@styles/bar.module.css" {
const stylesheet: any; // <- to be generated by TCM
export default stylesheet;
} And now the Summary
npx tcm --ambient --ambient-alias="@styles" --ambient-alias="src/styles" Then we can use Typescript's path aliases until relative ambient module declarations become a thing. This feature could even be used as prior art in a Typescript feature request. |
Hm, yeah I suppose that works. Could be worth it if you're willing to rewrite all your existing CSS imports. |
The current implementation doesn't allow to import the .css files using absolute import.
To support it, the .d.ts would need to do
instead of
The text was updated successfully, but these errors were encountered: