In VS2013 building stops when tsc exits with code 1. This was not the case in VS2012.
How can I run my solution while ignoring the tsc.exe error?
I get many The property 'x' does not exist on value of type 'y'
errors, which I want to ignore when using javascript functions.
Use a type assertion to ignore the 'Property does not exist on type' error in TypeScript, e.g. (obj as any). myProperty . Casting the object to any disables type checking and allows us to access any property on the object without getting any errors.
Use // @ts-ignore to ignore the type checking errors on the next line in a TypeScript file. If you use a linter, you might have to add a comment to also suppress linting errors when using ts-ignore - // eslint-disable-next-line @typescript-eslint/ban-ts-comment .
The "Property does not exist on type 'Window & typeof globalThis'" error occurs when we access a property that does not exist in the Window interface. To solve the error, extend the Window interface in a . d. ts file adding the property you intend to access on the window object.
The "Property does not exist on type String" error occurs when we try to access a property that does not exist on the string type. To solve the error, use an object instead of a string, or make sure you're accessing a valid built-in method on the string.
I know the question is already closed but I've found it searching for same TypeScriptException, maybe some one else hit this question searching for this problem.
The problem lays in missing TypeScript typing:
var coordinates = outerElement[0].getBBox();
Throws The property 'getBBox' does not exist on value of type 'HTMLElement'.
var outerHtmlElement: any = outerElement[0]; var coordinates = outerHtmlElement.getBBox();
Since TypeScript 1.6, the prefered casting operator is as
, so those lines can be squashed into:
let coordinates = (outerElement[0] as any).getBBox();
Of course if you'd like to do it right, which is an overkill sometimes, you can:
HTMLElement
HTMLElement
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
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
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