Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript compile error: 'declare' modifier not allowed for code already in ambient context

Tags:

typescript

I use the typescript definition file for breeze in my project (breeze.d.ts). When I compile my project, I got an error line 216:

'declare' modifier not allowed for code already in an ambient context.

If I simply delete declare it compiles successfully.

Does anyone experiencing the same problem?

Thanks.

like image 469
Bronzato Avatar asked Jul 29 '13 07:07

Bronzato


2 Answers

It happens when you are inside a declare section e.g.:

declare module Mod{
    declare var x;
}

Fix is the remove the inner declare keyword:

declare module Mod{
    var x;
}

So: The original typescript definition file you have is incorrect for the latest version of typescript.

like image 192
basarat Avatar answered Oct 20 '22 15:10

basarat


I got this error because I added ';' at the end of lines inside a declare module block:

declare module SomeModule {
    export function someFunction():any; <--- remove the ';'
    export function anotherFunc():any
}
like image 42
Flion Avatar answered Oct 20 '22 16:10

Flion