-
Notifications
You must be signed in to change notification settings - Fork 27
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
CSS Selectors using hyphens aren't compile-time checked due to square bracket access #26
Comments
The following alternate generated syntax will give compile-time errors with hyphen values. // This file is automatically generated.
// Please do not change this file!
const enum CssExports {
'item' = 'item',
'list' = 'list',
'root' = 'root',
'text' = 'text',
'text--small' = 'text--small',
'title' = 'title',
'title--small' = 'title--small',
}
declare const cssExports: typeof CssExports;
export = cssExports;
Potential problems
|
@jahredhope I'm happy to make a PR + tests if you guys are willing to accept it. |
I explored this option and it can fail in cases where users simply passed the entire ie. we're utilizing this in a project using Aurelia (with an aim to move slowly to React), so for our Aurelia components, we can't expose the CSS modules object to the templater of that particular framework.
I'm going to close this. |
Nevermind, I think I have a nice solution / patch to this problem. For example: // This file is automatically generated.
// Please do not change this file!
interface CssExports {
[key: string]: void; // <- this makes typos give you an error
'orb': string;
'orb-active-user': string;
'orb-exited-user': string;
'orb-list': string;
}
declare const cssExports: CssExports;
export = cssExports; ERROR in components\entity-search\entity-search.tsx
components/entity-search/entity-search.tsx
[tsl] ERROR in components\entity-search\entity-search.tsx(945,7)
TS2322: Type 'void' is not assignable to type 'string'. |
This approach has problems as pointed out by @MattsJones in his comment: Needs further investigation. |
Problem
I discovered when using this that if you write CSS selectors like this .my-selector, with a hyphen, when you import the CSS and access it with square bracket syntax, you lose compile-time checking on whether the selector / property exists or not.
Proposed solution(s)
a) Figure out if TypeScript has the ability to enforce checking when accessing something with square brackets.
b) If "a" is not possible, at least mention in documentation that this is a problem!
Notable TSConfig setup
noImplicitAny: false
The text was updated successfully, but these errors were encountered: