Skip to content

Auto import adds types to existing value imports under --importsNotUsedAsValues=error #39432

@itsMapleLeaf

Description

@itsMapleLeaf

TypeScript Version: 4.0.0-dev.20200705

Search Terms: auto import type

Code

// tsconfig.json
{
	"compilerOptions": {
		"target": "es2019",
		"module": "esnext",
		"noEmit": true,
		"allowJs": true,
		"importsNotUsedAsValues": "error",
		"strict": true,
		"moduleResolution": "node",
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"maxNodeModuleJsDepth": 1
	},
	"include": ["src", "types"]
}
// secret.ts
export type Secret = number
export const secret: Secret = 42
// main.ts
import { secret } from './secret'

// type `: Secret` after `newSecret`, then tab to auto-import it
// the import is added with the existing import,
// instead of as a type-only on a new line
const newSecret = secret + 42

Expected behavior:
When auto-importing a type in a type-only place, with "importsNotUsedAsValues": "error", it should always add a type import

Actual behavior:
If there is an existing import for where the type is coming from, it'll add it to that import, instead of creating a new type-only import

Here's a video of the bug:
hblyYQI3uv

Playground Link: Not applicable

Related Issues: Didn't see any

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions