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
Playground Link
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With