Auto-import quickfix : wrong strategy for import paths #15223
Labels
Bug
A bug in TypeScript
Domain: Quick Fixes
Editor-provided fixes, often called code actions.
Fixed
A PR has been merged for this issue
Milestone
TypeScript Version: 2.2.1
Actual behavior:
With the new auto-import quick fix in TS2.2 (usable in VS Code), the suggested paths for missing imports are behaving strangely.
If I already have something imported from one package, let's say :
import { Component } from '@angular/core';
then the auto-import quick fix for next missing imports from the same package will suggest the good solution :
"Add OnInit from existing import declaration from @angular/core"
resulting in :
import { Component, OnInit } from '@angular/core';
But if nothing is yet imported from one package, the suggested auto-imports from quick fix will be :
"Import OnInit from @angular/core/src/metadata"
"Import OnInit from @angular/core/src/core"
"Import OnInit from @angular/core/public_api"
"Import OnInit from @angular/core/core"
resulting for example in :
import { OnInit } from '@angular/core/core';
which is wrong.
Expected behavior:
As it's a common pattern for a package to do a main entry file (index.ts), re-exporting all the public API, and for TypeScript to have a consistent behavior, the auto-import quick fix should suggest the top-level path only :
"Import OnInit from @angular/core"
instead of low-level paths.
The text was updated successfully, but these errors were encountered: