Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript errors as warnings

I'm getting errors in typescript when writing basic javascript ES2015 functions. e.g. I get the following error for not declaring the type everywhere:

src\app\component.ts(44,18): error TS7006: Parameter 'a' implicitly has an 'any' type.

src\app\component.ts(44,21): error TS7006: Parameter 'b' implicitly has an 'any' type.

src\app\component.ts(45,20): error TS7006: Parameter 'p' implicitly has an 'any' type.

src\app\component.ts(45,23): error TS7006: Parameter 'n' implicitly has an 'any' type.

The 'problem' function is an ES2015 function like this:

this.filters = this.items
  .map(x => x.someProperty)
  .reduce((p,n) => p.concat(n), [])
  .sort((a, b) => {/* sort someway */})
  .reduce((p, n) => {/* do something */}, [])

I like the readabilty of this function and I know it works just fine. If I have to add type everywhere it defeats the purpose of having terser syntax.

I understood that Typescript was a superset of ES2015 but everything I write reports as an error (not warning) unless I specify every single type. It's a bit annoying and for some reason the errors crash my compiler.

That being said. I do like writing new code with strong types and I do like getting warnings. Just some in some functions it would be nice to turn off the checks.

Is there away to declare a function that ignores the rules or must I rewrite all my JavaScript in this way?

like image 991
chriskelly Avatar asked Apr 01 '16 09:04

chriskelly


1 Answers

Try setting "noImplicitAny": false in tsconfig compiler options:

{ 
     "compilerOptions": { 
         "noImplicitAny": false
     }
} 
like image 160
Amid Avatar answered Oct 10 '22 05:10

Amid