Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS7008: Member 'summary' implicitly has an 'any' type

Tags:

angular

After Updating to Angular 2 RC I got the following error:

error TS7008: Member 'summary' implicitly has an 'any' type.

in this line:

@Input() summary;

what's wrong?

Edit: Ok, seem like I get this error on ANY of my public variables.

like image 518
TheUnreal Avatar asked May 04 '16 16:05

TheUnreal


4 Answers

Perhaps you changed the value of the noImplicitAny attribute in your TypeScript compiler configuration... See the tsconfig.json file:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false // <-----
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

You could try to add a type on your property. Something like:

@Input() summary:string;
like image 145
Thierry Templier Avatar answered Nov 19 '22 06:11

Thierry Templier


This question already has correct answers, however to clarify and fully explain:

Solution 1 - Set this in your tsconfig.json:

    "noImplicitAny": false

Solution 2 Define the type for your variable like this:

    @Input() summary:string;

Explanation:

If you are converting plain JavaScript to TypeScript, you won't have any types assigned to your variables (or parameters) - since strict typing is what gives TypeScript its name.

In this case, when you have something like this variable (which has no type assigned):

@Input() summary;

Then TypeScript will implicitly assume that your variable has a type of 'Any' (i.e. it assumes that the variable can hold a value of any type). Furthermore, if you have the following set in your tsconfig.json:

{
  "compilerOptions": {
    ...
    "noImplicitAny": true,
  }
}

... then this tells the TypeScript compiler to throw errors if a variable or parameter implicitly has the 'Any' type. So, you can use the 1st solution to ignore all 'implicit any' errors, or use the 2nd solution (supply a type), and 'any' will not be implied.

Reference for TypeScript compiler options:

https://www.typescriptlang.org/docs/handbook/compiler-options.html

like image 26
Chris Halcrow Avatar answered Nov 19 '22 04:11

Chris Halcrow


just comment out this "noImplicitAny": false in tsconfig and it will work

like image 6
Gaurav Dubey Avatar answered Nov 19 '22 05:11

Gaurav Dubey


In Angular 12+ "strict": false, in tsconfig.json worked for me.

like image 3
Shiba Das Avatar answered Nov 19 '22 06:11

Shiba Das