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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -