I am recently having to deal with the following issue:
TS2339: Property 'activityTime' does not exist on type 'typeof import...'
In our project we commonly import our parameters.js as the following:
import * as params from 'parameters'
But parameters.js are kept locally and does not always contain optional configs. So the following code just gets flagged:
if (params.activityTime) {
// do something
}
We have quite a few of these throughout the project and adding @ts-ignore everywhere just gets messy.
I had thought about doing something like const p: any = params; in every place where params are imported, but that creates additional const in most of the files so I ended up discard that approach.
Without altering our parameters.js, is there a way to cast params as any?
You can declare the variable, so that TypeScript knows its type:
import * as params from './parameters';
declare const params: {
activityTime?: number;
};