The quick and dirty solution is to explicitly cast to any
(y as any).x
The "advantage" is that, the cast being explicit, this will compile even with the noImplicitAny
flag set.
The proper solution is to update the typings definition file.
Please note that, when you cast a variable to any
, you opt out of type checking for that variable.
Since I am in disclaimer mode, double casting via any
combined with a new interface, can be useful in situations where you
- do not want to update a broken typings file
- are monkey patching
yet, you still want some form of typing.
Say you want to patch the definition of an instance of y
of type OrginalDef
with a new property x
of type number
:
const y: OriginalDef = ...
interface DefWithNewProperties extends OriginalDef {
x: number
}
const patched = y as any as DefWithNewProperties
patched.x = .... //will compile