Typescript 2.4 Error: Variable StyledComponentClass from external module cannot be named.
See original GitHub issueVersion
2.1.1 Typescript: 2.4.2
Reproduction
Given a styled-component src/wrapper.tsx
import * as React from 'react';
import styled from 'styled-components';
const Wrapper = styled.header`
background-color: red;
height: 50px;
width: 100%;
`
export default Wrapper;
and tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["dom", "es2015", "es2016"],
"outDir": "dist",
"baseUrl": "./src",
"jsx": "react",
"sourceMap": true,
"declaration": true
},
"exclude": [
"node_modules"
]
}
The following error occurs:
[ts] Exported variable 'Wrapper' has or is using name 'StyledComponentClass' from external module "/path/project/node_modules/styled-components/typings/styled-components" but cannot be named.
Steps to reproduce
Expected Behavior
Doesn’t throw error
Actual Behavior
Throws error
[ts] Exported variable 'Wrapper' has or is using name 'StyledComponentClass' from external module "/path/project/node_modules/styled-components/typings/styled-components" but cannot be named.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Type from external module cannot be named - Stack Overflow
I am getting a very strange typescript error and I have no clue why this is happening: I have a a function "cleanArgs"...
Read more >False typescript error : WEB-42042 - YouTrack
The error is: TS4023: Exported variable 'selectedPrinterSelector' has or is using name 'Pages' from external module "[...]/UI" but cannot be named.
Read more >Kent C. Dodds on Twitter: "@pelotom I did see that same ...
TS4023: Exported variable 'X' has or is using name 'Y' from external module 'a/file/path' but... I'm attempting to create a set of external...
Read more >Parameter 'x' of public method from exported class...external ...
error : Parameter 'x' of public method from exported class...external module “z” but cannot be named. HandsomeChow 于 2021-09-09 09:42:19 发布 265 收藏....
Read more >framework from aesthetic-suite - Giter VIP
JavaScript 4.11% CSS 0.01% HTML 1.69% TypeScript 86.78% EJS 7.41% react css ... and CSS variables for high performance, low filesize, and efficient...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, I though it was not exported, but it was. If you write your code that way, it should work:
We cannot fix this on our side, that is TypeScript’s intended behavior, but the fix is under consideration.
Yes, that is annoying TS error that prevents writing declaration files when they use inferred types that are defined externally. There’re 2 issues here:
StyledComponentClass
is not exportedThe first we can fix, and we will. The second you’d have fix yourself.