Skip to content

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

@jens-duttke

Description

@jens-duttke
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;
		}
	}
},

Activity

c0gnize

c0gnize commented on Oct 12, 2020

@c0gnize
Contributor

Why not, good idea!

c0gnize

c0gnize commented on Oct 12, 2020

@c0gnize
Contributor

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

added a commit that references this issue on Mar 6, 2025
3a9d16e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jens-duttke@c0gnize

        Issue actions

          Feature request: Custom function to generate the d.ts file · Issue #19 · Megaputer/dts-css-modules-loader