Encountering an error in TypeScript:
error TS2339: Property 'FOO' is not found in type '{ stuff ... 201 more ...; }'.
Constants.FOO.forEach((item) => {
~~~
Arising from this scenario:
// Constants.js
const Constants = {
ABC: 123,
WWW: 'COM',
// ...
}
// further down in the same file:
Constants.FOO = [
Constants.ABC,
Constants.WWW,
]
Subsequently in the file that imports this:
import Constants from 'Constants'
// Seeing the error highlights indicating the error message above...
Constants.FOO.forEach((item) => {
console.log(item)
// 123
// 'COM'
})
How can I tackle this issue? Is there a way to address it without needing to rewrite the implementation of Constants
? Since in my case, there are numerous occurrences of this error for various properties on Constants
that are added after the object is created.
Keep in mind that Constants.js
is a JavaScript file and not a TypeScript file, so ideally avoiding the conversion of Constants.js to TypeScript would be preferable due to the extensive work involved in our situation. Is there another workaround available?