Assertion Signatures

canvas could be null or undefined so can't call getContext

with optional chaining now we let TS now to only call getContext if it is not null or undefined but we now get the issue that canvas will be an HTMLElement, not an HTMLCanvasElement, so that getContext property is not defined in its interface.


Double Assertion Signatures (dangerous)


Very useful when TS won’t let you do what you know is right (specially when using third party APIs) but very dangerous, much more than using any.


Copyright 2023 © Borja Leiva

Made within London