Giter VIP home page Giter VIP logo

Comments (5)

silbinarywolf avatar silbinarywolf commented on May 30, 2024

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;
[tsl] ERROR in C:\javascript\my-component.tsx(28,33)
      TS2339: Property 'titlae--small' does not exist on type 'typeof CssExports'.

Potential problems

from css-modules-typescript-loader.

silbinarywolf avatar silbinarywolf commented on May 30, 2024

@jahredhope I'm happy to make a PR + tests if you guys are willing to accept it.
If I put in the effort will this get merged?

from css-modules-typescript-loader.

silbinarywolf avatar silbinarywolf commented on May 30, 2024

I explored this option and it can fail in cases where users simply passed the entire styles variable to another value.

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.

@autoinject
@useView(PLATFORM.moduleName('./my-component.html'))
export class MyComponent  {
	private readonly styles = styles;
}

I'm going to close this.

from css-modules-typescript-loader.

silbinarywolf avatar silbinarywolf commented on May 30, 2024

Nevermind, I think I have a nice solution / patch to this problem.
We just define an index signature that returns void.

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'.

from css-modules-typescript-loader.

silbinarywolf avatar silbinarywolf commented on May 30, 2024

This approach has problems as pointed out by @MattsJones in his comment:
#29 (comment)

Needs further investigation.

from css-modules-typescript-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.