2

I perfectly know why the error is raised but I can't find a way to suppress it (that is not // @ts-ignore). I'm using style-loader with the inline syntax:

import styles from '!style-loader?injectType=lazyStyleTag!css-loader!vendor/style.css';

Cannot find module '!style-loader?injectType=lazyStyleTag!css-loader!vendor/style.css'' or its corresponding type declarations.

How should I "instruct" TypeScript that the import is legit?

EDIT: declaration as per answer:

declare module '!style-loader?*' {
  const value: { use: (options?: Record<string, any>) => void, unuse: () => void };
  export default value;
}

1 Answer 1

2

Typescript allows you to declare a custom module import on your own, specifically you might use a wildcard module declarations so following things:

  • Declare your custom typings files such as ./typings/index.d.ts
declare module '!style-loader?*' {
  const value: any;
  export default value;
}
  • Include this typings dir into your tsconfig.json:
{
  // ...
  "include": ["...", "typings"]
}

One more thing, you need to check which version of Typescript supports this wildcard module declaration.

Sign up to request clarification or add additional context in comments.

1 Comment

Amazing, thanks a lot, i've updated the answer to a better declaration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.