I have an object foo
that is used all around the codebase and need to access the property bar
from it. However, due to specific circumstances ts thinks that property does not exist on it, even though it in fact does. So I am getting the redline with this message all over the place:
Property 'foo' does not exist on type 'bar'
In my ts-config file, I would like to set it to ignore all these errors, but ONLY for the foo
variable.
Can this be done?
You can't do this in tsconfig
, there is no such setting. You can do one of several things.
Use a type assertion to any
. Using this all property accesses are allowed:
(bar as any).foo
Another option is to just suppress the error. You can use @ts-ignore
to suppress ALL errors for the next line
//@ts-ignore
bar.foo // no error
Note: You might be better off finding the reason for the error, or augmenting the type or charging the type of the variable to something that incudes foo
but without more details it is difficult to propose a solution.