I have only one export default
line in my code. However, in WebStorm with Typescript, I get this TS Error:
Ts2528: a module cannot have multiple default exports
Here is the code:
ts import { ModelCreator } from 'entities/model-creator' export default ModelCreator()
There are two different types of export, named and default. You can have multiple named exports per module but only one default export.
Every module can have two different types of export, named export and default export. You can have multiple named exports per module but only one default export. Each type corresponds to one of the above syntax.
Default Exports: Default exports are useful to export only a single object, function, variable. During the import, we can use any name to import.
Use named exports to export multiple functions in React, e.g. export function A() {} and export function B() {} . The exported functions can be imported by using a named import as import {A, B} from './another-file' . You can have as many named exports as necessary in a single file.
Quick Way
As sometimes you can just reopen a file as stated in other answers, it doesn't always help, however.
Update: Dec 10, 2020. The previous option (see below) is not available in new versions of WebStorm. To restart the TS service now, you can use the following option:
See more details on TypeScript tool window help center page.
Previous functionality (prior versions)
When you see lags like this one (and other weirdness from TS service), you can restart the TypeScript service by opening a TypeScript tool window and clicking on the "Restart" button (3rd button on the right side of the panel):
I had the same error. After restarting WebStorm it worked again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With