Description
π Search Terms
Namespace, use before declaration, initialized variable
π Version & Regression Information
- This is the behavior in every version I tried.
β― Playground Link
π» Code
export namespace A{
export namespace A1 {
export const fn = () => "string"
}
export namespace A2{
// should report use before initialization here
export const array = [A3.value]
}
export namespace A3{
export const value = A1.fn()
}
}
π Actual behavior
Hi, using typescript V5+, the code provided did not reports any errors, and doesn't work in runtime due to use before initialization.
π Expected behavior
It is expected that TS2448 and TS2454 will be reported.(use before declaration)
These are reported if the namespace keyword is omitted in the code example and it should be the same when namespaces are used.
It seems files with namespaces are always transpiled with the same format using any TS configuration. (everything becomes iife)
Additional information about the issue
Optimistically additional support for namespace will be added, such as not transforming the entire file to iife when namespaces are used- which happen on any configuration.
And maybe even an option to make a code like I've sent work, by isolating these namespaces properly, and resort their order by their variable dependencies between themselves, and report when cycling variable dependency between namespaces exists.