3

We have an Angular 11 application with strict mode turned on. It has these values in the compilerOptions configurtation in tsconfig.json:

"strict": true,
"noImplicitReturns": true,

Now we want to use an external library (leaflet geoman). The library is imported like this:

import * as L from 'leaflet';
import '@geoman-io/leaflet-geoman-free';

Unfortunately it includes implicit any types as well as implicit any return types:

Parameter 'options' implicitly has an 'any' type.
'setLang', which lacks return-type annotation, implicitly has an 'any' return type

How can I tell the compiler to ignore these errors from the module during compilation but keep strict mode turned on for the rest of the project?

lampshade
  • 2,470
  • 3
  • 36
  • 74
  • Leaflet and leaflet-geoman-free, accordingly to the npmjs.com package pages, already have the proper types included. Check if the @types are included in the tsconfig file – Andrea Alhena Mar 29 '21 at 09:57
  • @AndrewAlhena The TypeScript implementaion seems not to be ready yet, see: [Typescript implementation #790](https://github.com/geoman-io/leaflet-geoman/issues/790). – lampshade Apr 19 '21 at 08:22

2 Answers2

6

You could call the compiler and use the --skipLibCheck flag to achieve what you want.

--skipLibCheck is added in TypeScript 2.0: skiplibcheck

tsc --skipLibCheck

You can read more about why to use it in this thread:

Usage of the TypeScript compiler argument 'skipLibCheck'

Filip Huhta
  • 2,043
  • 7
  • 25
1

Even though the @types are included in the leaflet and leaflet-geoman-free npm packages, you should be able to use the "as" keyword to tell TypeScript that an element is respectful of a certain interface / class.

const x = fn() as IYourInterface;

If you know the structure of the return data, you can define an interface on your own. If you want, you can ignore the typescript triggered error by adding this comment before the line that's triggering the error:

// @ts-ignore
line of code that triggers the error

Obviously, if you are sure that the package is lacking some type definitions, the best way is to create an interface by yourself.

Andrea Alhena
  • 986
  • 6
  • 9