TS2304 when consuming a non-module global namespace object
Steps to reproduce
https://github.com/HolgerJeromin/reproducible-examples/tree/tsgo-2214-namespace
I have a non-module ("module": "None") project which creates a namespace.
// file: nonmodule/nonmodule.ts
namespace myNamespace {
export const version = "1.0.0";
}
tsconfig.json
{
"$schema": "http://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": true,
"module": "None",
"target": "ES2022",
"types": [],
"strict": true
},
"files": ["nonmodule.ts"]
}
With a module I work with this data.
// file: src/main.ts
let _foo = myNamespace.version;
tsconfig.json
{
"$schema": "http://json.schemastore.org/tsconfig",
"references": [{"path": "../nonmodule"}],
"compilerOptions": {
"module": "es2022",
"target": "ES2022",
"types": [],
"strict": true
},
"files": ["main.ts"]
}
Behavior with [email protected]
Compiles without problems.
Behavior with tsgo
src/main.ts:1:12 - error TS2304: Cannot find name 'myNamespace'.
1 let _foo = myNamespace.version;
~~~~~~~~~~~
Found 1 error in src/main.ts:1
"none" as a module setting has been removed, we just haven't errored on it yet.
Are you looking for moduleDetection=legacy?
Thanks for your answer.
We use module:none since 10 years.
It always felt better to explicit define what we target and not to rely on some guessing and changing the guessing mode for the compiler.
When I change nonmodule\tsconfig.json
- "module": "None",
+ "moduleDetection": "legacy",
The error is not fixed.
Compile of nonmodule project still works like a charm, but the namespace is still not resolved in src folder.
"none" as a module setting has been removed, we just haven't errored on it yet.
Ah. Found #2085 for that.