-
Notifications
You must be signed in to change notification settings - Fork 372
Use import type
for types instead of import
#607
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
Conversation
- importing types without 'import type' was problamatic with svelte vite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR! 🙇
Personally, I don't use import/export type
that much but I get that some tooling might require it. The problem with this PR is that right now our tests can't catch any mistakes related to this. I can change import
to import type
and the other way around and CI still passes.
How can we verify that current changes work?
'BigNumberish', | ||
], | ||
'@ethersproject/providers': ['Provider', 'TransactionRequest'], | ||
ethers: ['Signer', 'utils', 'Contract', 'ContractFactory', 'PayableOverrides', 'BytesLike', 'BigNumberish'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change this line to:
ethers: ['Signer', 'utils', 'Contract', 'ContractFactory', 'PayableOverrides', 'BytesLike', 'BigNumberish'], | |
'type ethers': ['Signer', 'utils', 'Contract', 'ContractFactory', 'PayableOverrides', 'BytesLike', 'BigNumberish'], |
(merge with next line) and all tests still pass.
Do you also want me to edit tests so when something that is a type imported without import type or the other way around, we catch it in the tests? |
|
|
scripts/.eslintrc.js
Outdated
@@ -0,0 +1,6 @@ | |||
/** @type {import("eslint").Linter.Config} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that it was giving ide errors because the folder had files with console.logs but the root eslint config doesn't allow console.logs.
But scripts folder contains files for cli scripts.
So i suppose it's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm but this way this file is also not used by anything.... I think the real solution would be to enforce root eslint config for every single file (right now it's only for code that is actually published) and then ignore valid console.logs with eslint ignore comments. I'd remove this from this PR and do this in a separate one.
tsconfig.json
Outdated
@@ -9,7 +9,8 @@ | |||
"sourceMap": true, | |||
"composite": true, | |||
"incremental": true, | |||
"exactOptionalPropertyTypes": true | |||
"exactOptionalPropertyTypes": true, | |||
"importsNotUsedAsValues": "error" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we enforce this only in packages/target-ethers-v5/tsconfig.json
? I don't feel that it's necessary to use accross the whole codebase.
@DeepDoge thanks! This flag |
@krzkaczor I mean, I believe it would be good that if we use it for the whole codebase. It's more consistent and I already updated the whole codebase for it. But if you really don't want it for the whole codebase, I can only scope it for, ethers v5, v4 and web3 tests. EDIT: Left for my military service, brb next month. |
Yes, I would prefer to do it like this. I am not sure if there is an automatic way to enforce proper use of
Good luck! :) |
@krzkaczor can you check now? |
@@ -20,8 +20,12 @@ describe('TypeChain x Hardhat', () => { | |||
const artifact = require('../artifacts/contracts/Counter.sol/Counter.json') as { abi: Interface; bytecode: string } | |||
|
|||
const counterFactory1 = new Counter__factory() | |||
counterFactory1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
Superseded by #636 |
Made it generate type imports with
import type
instead ofimport
alone.What I changed:
createImportDeclaration
andcreateImportTypeDeclaration
functions were both doing the exact same thing, nowcreateImportTypeDeclaration
imports withimport type
.createImportsForUsedIdentifiers
used, if themoduleSpecifier
is starting withtype
, it's usingcreateImportTypeDeclaration
for it instead ofcreateImportDeclaration
.I did this because this is how it's suppose to be and it was causing problems with Svelte's Vite.