-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraints
Description
In Node.JS the following pattern can be used to load optional dependencies:
try {
var foo = require('foo')
var fooVersion = require('foo/package.json').version
} catch (er) {
foo = null
}
if ( notGoodFooVersion(fooVersion) ) {
foo = null
}
// .. then later in your program ..
if (foo) {
foo.doFooThings()
}
This doesn't work with an import foo = require() because import cannot be inside a try block. Dynamic imports have to be async, which unlike the above, requires the calling code to be async. How about having synchronous dynamic module importing which would allow an import inside a try block but load synchronously?
levp and ORESoftware
Metadata
Metadata
Assignees
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraints