Allow dynamic usage of import = require
syntax
#60884
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
๐ Search Terms
dynamic import, require, verbatimmodulesyntax
โ Viability Checklist
โญ Suggestion
I propose that
import = require()
should be allowed anywhere arequire()
statement is allowed (under appropriate module settings).๐ Motivating Example
I've been trying to convert a commonjs project to verbatimModuleSyntax. Currently dynamic JSON imports are written as
which are rewritten as
Promise.resolve().then(() => require('./foo.json'));
by TS due to my module setting. Theimport()
syntax currently has the advantage that TS statically analyzes and provides types for the imported JSON.I'd like to convert the JSON import to a
require()
call, however, a barerequire()
loses static analysis. Therefore, I'd like to be able to usein order to have type inference and static analysis of the json file (also to have it copied to the output build).
(using a node
import()
-from-CJS is not available to me at this time)๐ป Use Cases
require()
s.Somewhat relates to #60598
The text was updated successfully, but these errors were encountered: