typescript - Can a function have `multiple optional parameters' that is simultaneously required? -
i'm trying polyfill createimagebitmap
function.
[nointerfaceobject, exposed=window,worker] interface imagebitmapfactories { promise createimagebitmap(imagebitmapsource image, optional long sx, long sy, long sw, long sh); };
it seems function allows createimagebitmap(image)
, createimagebitmap(image, sx, sy, sw, sh)
not else, example, createimagebitmap(image, 0, 0)
.
how can in typescript? cannot by:
function createimagebitmap(image: any, sx?: number, sy: number, width: number, height: number) { }
... fails compile.
looks need function overloading:
function createimagebitmap(image: any); function createimagebitmap(image: any, sx: number, sy: number, width: number, height: number); function createimagebitmap(image: any, sx?: number, sy?: number, width?: number, height?: number) { // ... }
Comments
Post a Comment