When you import the library using
import * as library from 'library';
, you are effectively bringing the library into your code, allowing you to utilize it. If you attempt to use the library without importing it first, you will likely encounter an error. There may be instances where the library is already imported elsewhere in your application, and you simply want to make use of it. In such cases, you can do so without any issues – the application will still function properly. However, if the TypeScript compiler identifies an error (and your IDE highlights it accordingly), it may be due to a lack of a typing definition file for the library (.d.ts). To address this, you can add the following declaration:
declare var library: any;
This statement informs the TypeScript compiler that 'library' does exist, thus preventing compilation errors (as well as eliminating IDE notifications).