Skip to content

import foo = require(...) should not be considered deprecated in the spec #11340

Closed
@basarat

Description

@basarat

Reading the official spec : https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#1133-import-require-declarations

It says :

exist for backward compatibility with earlier versions of TypeScript

However for a vast number of npm modules out there that do export = someFunction there is no ES6 syntax that TypeScript approves of i.e import * as someFunction from "someFunction" will complain that it resolves to a non module entity.

Suggestion:

Either of these would be fine:

  • import/require should not be marked as deprecated as there is no alternative
  • import * as someFunction from "someFunction" should be allowed.

Workaround : people (and I) have been doing module someFunction{} to quieten the compiler and then import * as works. I am probably wrong but would like an official way forward.

/cc @blakeembrey 🌹

Activity

added
BugA bug in TypeScript
SpecIssues related to the TypeScript language specification
on Oct 4, 2016
HerringtonDarkholme

HerringtonDarkholme commented on Oct 4, 2016

@HerringtonDarkholme
Contributor

For short term I think the first option is a fairly easy solution.

But I'm very worried about long term compatibility between TS, commonjs and ESModule. Namely, should allow import DefaultExport from "some-module" when it is declared declare module "some-module" { export = ... }

Related issues and proposals:

#9562

nodejs/node-eps#26

https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md#54-es-consuming-commonjs

After reading these issues I think a new compiler flag that do the type checking for synthetic import and code generation as well.

changed the title [-]import/require deprecation[/-] [+]import foo = require(...) should not be considered deprecated in the spec[/+] on Nov 15, 2017
RyanCavanaugh

RyanCavanaugh commented on Jul 20, 2020

@RyanCavanaugh
Member

The spec is now an "archived" artifact and we won't be tracking defects against it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

SpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @basarat@DanielRosenwasser@HerringtonDarkholme@ahejlsberg@RyanCavanaugh

      Issue actions

        import foo = require(...) should not be considered deprecated in the spec · Issue #11340 · microsoft/TypeScript