Skip to content

Feature request: Custom function to generate the d.ts file #19

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

Closed
jens-duttke opened this issue Oct 10, 2020 · 2 comments
Closed

Feature request: Custom function to generate the d.ts file #19

jens-duttke opened this issue Oct 10, 2020 · 2 comments

Comments

@jens-duttke
Copy link
Contributor

After the latest update of style-loader and mini-css-extract-loader (where esModule defaults to true), the compilation does not work anymore.

I was able to fix that by replacing

import * as styles from './styles.module.scss';

by

import styles from './styles.module.scss';

But now the generated "styles.module.d.ts" file does not match, since TypeScript complains about the missing default export.
I would need to change that to:

declare const styles: {
	// My classes here
};

export default styles;

Would it make sense to implement a configuration option, which get's a list of all classes as parameter, and which returns a string, which is then used as content of the .d.ts file?

	{
	loader: 'dts-css-modules-loader',
	options: {
		banner: '// This file is automatically generated. Do not modify this file manually -- YOUR CHANGES WILL BE ERASED!',
		customDeclaration: function (classes) {
			let typings = 'declare const styles: {\n';

			for (const c of classes) {
				typings += `\t'${c}': string;\n`;
			}

			typings += '};\n\nexport default styles;\n';

			return typings;
		}
	}
},
@c0gnize
Copy link
Contributor

c0gnize commented Oct 12, 2020

Why not, good idea!

@c0gnize
Copy link
Contributor

c0gnize commented Oct 12, 2020

@jens-duttke you can use this option to customize end-of-line characters (issue #18)

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

No branches or pull requests

2 participants