Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

1039 - Initializers are not allowed in ambient contexts.

🔍 Regex Patterns

regexFind: /\s*=\s*[^;]+/
regexReplace: 

💡 Suggestion

Remove initializer from ambient context. Ambient contexts (declare module, declare namespace) can only contain type declarations, not initializers or executable code.

📝 Examples

Example 1: Number initializer in ambient module

declare module "my-module" {
-  const value: number = 42
+  const value: number
}

Explanation: Remove initializer from const declaration in ambient module

Example 2: String initializer in ambient namespace

declare namespace MyNamespace {
-  const config: string = 'default'
+  const config: string
}

Explanation: Remove initializer from const declaration in ambient namespace

🖼️ Visual Output

Command

npx tsc ./docs/1039/index.ts --noEmit --pretty

Result

docs/1039/index.ts:2:25 - error TS1039: Initializers are not allowed in ambient contexts.

2   const value: number = 42
                        ~~~

OR (without --pretty flag):

docs/1039/index.ts(2,25): error TS1039: Initializers are not allowed in ambient contexts.