patternjavascriptCritical
Ignore Typescript Errors "property does not exist on value of type"
Viewed 0 times
typescriptpropertyerrorsexistignoredoesnotvaluetype
Problem
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
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.Solution
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:
Throws
The easiest way is to explicitly type variable as
Edit, late 2016
Since TypeScript 1.6, the prefered casting operator is
Other solutions
Of course if you'd like to do it right, which is an overkill sometimes, you can:
The problem lays in missing TypeScript typing:
var coordinates = outerElement[0].getBBox();Throws
The property 'getBBox' does not exist on value of type 'HTMLElement'.The easiest way is to explicitly type variable as
anyvar outerHtmlElement: any = outerElement[0];
var coordinates = outerHtmlElement.getBBox();Edit, late 2016
Since TypeScript 1.6, the prefered casting operator is
as, so those lines can be squashed into:let coordinates = (outerElement[0] as any).getBBox();Other solutions
Of course if you'd like to do it right, which is an overkill sometimes, you can:
- Create own interface which simply extends
HTMLElement
- Introduce own typing which extends
HTMLElement
Code Snippets
var coordinates = outerElement[0].getBBox();var outerHtmlElement: any = outerElement[0];
var coordinates = outerHtmlElement.getBBox();Context
Stack Overflow Q#18083389, score: 417
Revisions (0)
No revisions yet.