No errors for TypeScript `import` types
See original GitHub issueDocs on import
types: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
Reduced test case (all dependencies are latest):
// ./cypress/test.ts
// Expected error, got one
// Unexpected path "../app/helpers/api" imported in restricted zone
import Api from '../app/helpers/api';
// Expected error, but got none
type Api = typeof import('../app/helpers/api');
// .eslintrc.js
const config = {
extends: ['plugin:import/typescript'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
plugins: ['import'],
rules: {
'import/no-restricted-paths': [
2,
{
basePath: '.',
zones: [
{
target: './cypress',
from: './app',
},
],
},
],
},
}
module.exports = config;
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Do I need to use the "import type" feature of TypeScript 3.8 if ...
Short answer: Being more explicit by using import type and export type statements seem to yield explicable benefits by safeguarding against ...
Read more >Documentation - TypeScript 3.8
import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there's no remnant of...
Read more >No errors for TypeScript `import` types · Issue #1675 - GitHub
Dynamic imports aren't usually checked, because they aren't forced to be static, and it's impossible to reliably statically know the import path ...
Read more >TypeScript errors and how to fix them
Common Errors Below you find a list of common TypeScript errors along with the buggy code and its fixed version.
Read more >consistent-type-imports | typescript-eslint
TypeScript allows specifying a type keyword on imports to indicate that the export exists only in the type system, not at runtime.
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
I am feeling free to ask for an additional parameter for each zone.
Is it possible to allow typescript special imports for types?
It would be nice to disallow imports which stay in compiled javascript but allow imports of type in this way. The parameter for the zone could be named as
"allowTypeImports": true
None of these run any code so they should be allowed: