Closed
Description
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 alternativeimport * 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 🌹
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
HerringtonDarkholme commentedon Oct 4, 2016
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 declareddeclare 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.
[-]import/require deprecation[/-][+]import foo = require(...) should not be considered deprecated in the spec[/+]DanielRosenwasser commentedon Nov 15, 2017
Hard link: https://github.com/Microsoft/TypeScript/blob/4b96edf72faf6f9b6b464e148c9c02eac96aa4bd/doc/spec.md#1133-import-require-declarations
Also see #16093
RyanCavanaugh commentedon Jul 20, 2020
The spec is now an "archived" artifact and we won't be tracking defects against it anymore.