Skip to content

Import suggestion/fix should respect ES module target #31219

Closed
@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 3.4.1

Search Terms: import suggestion fix module esnext es modules target assignment

Code

// ./typings.d.ts
declare module 'foo' {
    const _default: number;
    export = _default;
}
// ./tsconfig.json
{
    "compilerOptions": {
        "module": "esnext"
    }
}
// main.ts
foo;

When I activate the import suggestion/fix for foo:

image

Expected behavior:

import * as foo from "foo";

foo

Actual behavior:

// Error:
// Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
import foo = require("foo");

foo

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Quick FixesEditor-provided fixes, often called code actions.Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Fix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions