Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.31 KB

File metadata and controls

54 lines (42 loc) · 1.31 KB

1040 - '{0}' modifier cannot be used in an ambient context.

🔍 Regex Patterns

regexFind: /async\s+function\s+([a-zA-Z_$][a-zA-Z0-9_$-]*)/
regexReplace: function $1

💡 Suggestion

Remove async modifier from ambient context. Ambient contexts (declare module, declare namespace) can only contain type declarations, not executable code with modifiers like async.

📝 Examples

Example 1: Async function in declare module

declare module "test" {
-  async function helper(): Promise<void>
+  function helper(): Promise<void>
}

Explanation: Remove async modifier from function declaration in ambient module

Example 2: Async function in declare namespace

declare namespace MyNamespace {
-  async function process(): Promise<string>
+  function process(): Promise<string>
}

Explanation: Remove async modifier from function declaration in ambient namespace

🖼️ Visual Output

Command

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

Result

docs/1040/index.ts:2:3 - error TS1040: 'async' modifier cannot be used in an ambient context.

2   async function helper(): Promise<void>
    ~~~~~

OR (without --pretty flag):

docs/1040/index.ts(2,3): error TS1040: 'async' modifier cannot be used in an ambient context.