angular 2 typescript An implementation cannot be declared in ambient contexts

前端 未结 6 1434
刺人心
刺人心 2021-01-07 23:02

I am new to typescript and I am trying to create a function for an angular 2 directive. Can anyone explain, in language for n00bs, what the error is trying to tell me when I

相关标签:
6条回答
  • 2021-01-07 23:22

    I think this happened to me, because I accidentally edited one of the files in node_modules. This fixed it for me:

    rm -r node_modules
    npm install
    
    0 讨论(0)
  • 2021-01-07 23:23

    I ran across this rather unusual compile-time Typescript error error TS1183: An implementation cannot be declared in ambient contexts.

    It started after I had copy/pasted some sourcecode that had export declare class. I noticed when I changed it to export class this error went away.

    Change This:

    export declare class Foo {
    }
    

    To This:

    export class Foo {
    }
    
    0 讨论(0)
  • 2021-01-07 23:27

    error TS1183: An implementation cannot be declared in ambient contexts. Solution :Removed node module and reinstall it.

    0 讨论(0)
  • 2021-01-07 23:31

    I had the same error and fixed it by typing:

    npm install --save typescript@latest
    

    package.json now has the latest ts version and ts compiler is 2.2.2.

    0 讨论(0)
  • 2021-01-07 23:35

    An implementation cannot be declared in ambient contexts

    You most probably have your file named as foo.d.ts instead of foo.ts. That marks it as a declaration file (more on that https://basarat.gitbooks.io/typescript/content/docs/types/ambient/d.ts.html) and you cannot put logic in these as you are declaring what logic exists elsewhere.

    0 讨论(0)
  • 2021-01-07 23:47

    I fixed it by doing: npm install rxjs

    0 讨论(0)
提交回复
热议问题