noImplicitAny

The noImplicitAny compiler option is used to check whether function declarations or expressions have not been strictly typed, and will therefore (by default) return an any type. This can be explained through a simple code sample, as follows:

declare function testImplicitAny(); 
 
function testNoType(value) { 
} 

Here, we start with the declaration of a function named testImplicitAny. We then create a function named testNoType that has a single parameter named value. If we compile this code with the noImplicitAny compile option set to true, the compiler will generate the following errors:

error TS7010: 'testImplicitAny', which lacks return-type annotation, implicitly has an 'any' return type.
error TS7006: Parameter 'value' implicitly has an 'any' type.  

The first error is telling us that we have declared a function, but have not specified what type this function will return. Even if the function does not return anything, we will need to specify void as the return type.

The second error is telling us that the parameter value does not have a type specified. We can easily fix these errors by inserting the correct types, as follows:

declare function testImplicitAny() : void; 
 
function testNoType(value: string) { 
} 

Here, we have specified that the return type of the testImplicitAny function should be of type void, and we have specified that the type of the value parameter for the testNoType function should of type string.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.254.35