Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
basarat opened this issue Oct 4, 2016 · 3 comments
Closed
Assignees
Labels
Spec Issues related to the TypeScript language specification

Comments

@basarat
Copy link
Contributor

basarat commented Oct 4, 2016

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 🌹

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Spec Issues related to the TypeScript language specification labels Oct 4, 2016
@HerringtonDarkholme
Copy link
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.

@mhegazy mhegazy removed the Bug A bug in TypeScript label Dec 7, 2016
@DanielRosenwasser DanielRosenwasser changed the title import/require deprecation import foo = require(...) should not be considered deprecated in the spec Nov 15, 2017
@DanielRosenwasser
Copy link
Member

Hard link: https://github.com/Microsoft/TypeScript/blob/4b96edf72faf6f9b6b464e148c9c02eac96aa4bd/doc/spec.md#1133-import-require-declarations

Also see #16093

@RyanCavanaugh
Copy link
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
Labels
Spec Issues related to the TypeScript language specification
Projects
None yet
Development

No branches or pull requests

6 participants