Closed
Description
Bug Report
Namespace importing a cjs module described with an any
type from an es module leads to a debug failure.
🔎 Search Terms
Debug Failure. Unhandled type 1
🕗 Version & Regression Information
- This is a crash in 4.9.0-dev.20221007 and 4.8.4
⏯ Playground Link
Can't because it's multiple files.
💻 Code
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"type": "module",
"module": "index.mjs",
"dependencies": {
"typescript": "^4.9.0-dev.20221007"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "NodeNext",
"strict": true
}
}
index.mts
import * as namespaceImport from "./other.cjs";
console.log(namespaceImport);
other.cjs
// note: this is described by other.d.cts
module.exports.test = () => 5;
other.d.cts
declare const __: any;
export = __;
🙁 Actual behavior
Running tsc
:
V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:99472
throw e;
^
Error: Debug Failure. Unhandled type 1
at resolveStructuredTypeMembers (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:49660:30)
at cloneTypeAsModuleType (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:43230:38)
at resolveESModuleSymbol (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:43209:36)
at getTargetOfNamespaceImport (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:42412:28)
at getTargetOfAliasDeclaration (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:42640:28)
at resolveAlias (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:42681:30)
at checkAliasSymbol (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:72981:26)
at checkImportBinding (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:73096:13)
at checkImportDeclaration (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:73147:29)
at checkSourceElementWorker (V:\any-cjs-tsc\node_modules\typescript\lib\tsc.js:73614:28)
Note: type 1 is TypeFlags.Any
🙂 Expected behavior
Should pass type checking.
Why?
We use the file with declare const __: any; export = __
in Deno in order to give certain modules an any type. Now when adding impliedNodeFormat
when creating a source file in order to allow importing npm packages, I had to make this module CJS because it has export =
and that surfaced this issue.