-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Is it possible to satisfy the no-duplicate-imports rule with type imports? #41
Comments
Should be. Try |
I don't think that is valid syntax. |
You're right, sorry. I'm not sure then. I'd just use destructing like normal: import * as React from 'react'
const { StatelessComponent } = React |
If you'd like, feel free to verify the behaviour is the same as with StandardJS. They're using it from https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md, so there may be a deviation in TSLint if your code was valid with ESLint. |
I think the rule is valid for js, just not sure it should be applied to ts. I have disabled the rule in local config, but I would be interested to see if there is a better solution. |
Both imports are identical in JS vs TS, there's no real difference. If what you mean is about namespace React {
export interface StatelessComponent { }
}
import StatelessComponent = React.StatelessComponent This would be improved 10x if TypeScript supported destructing in this case, which i think is pretty important for property parity with JS nowadays (e.g. |
Ah, sorry, I just saw you were talking about type imports in the title 😄 I regularly overlook the title and just read the body, sorry for the confusion and oversight. |
@garth what you should do in case of importing react stuff is following: tsonfig: {
"compileOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
} now you can: import React, { StatelessComponent } from 'react'; PRO TIP: instead of importing super long/verbose PRO TIP 2: We've gone even further and import only what the module needs. So for transforming JSX to function calls we import only // now you got both runtime function and typescript type in one import
import {createElement, SFC} from 'react' tsonfig: {
"compileOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react",
"jsxFactory": "createElement",
}
} or since TS 2.9 you can import types inline where your need them, so you solely import only runtime values via standard ES2015 modules import React from 'react'
type Props = {...}
const Hello: import('react').SFC<Props> = (props) => <div>Hello</div> |
Is it possible to import from both a node_module and type in a single import statement?
The text was updated successfully, but these errors were encountered: