Skip to content

Commit

Permalink
Add overload signatures for rasterize, and convert to function, see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 5, 2025
1 parent 6d8fabc commit 0ce4d1e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/util/rasterized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ export type RasterizedOptions = {
imageOptions?: ImageOptions;
};

// Overload signatures, when wrap is true, the return type is a Node, otherwise it is an Image
export function rasterized( node: Node, providedOptions?: RasterizedOptions & { wrap?: true } ): Node;
export function rasterized( node: Node, providedOptions: RasterizedOptions & { wrap: false } ): Image;

// Implementation signature (must be compatible with the overloads)
/**
* Returns a Node (backed by a scenery Image) that is a rasterized version of this node. See options, by default the
* image is wrapped with a container Node.
*/
export const rasterized = ( node: Node, providedOptions?: RasterizedOptions ): Node => {
export function rasterized( node: Node, providedOptions?: RasterizedOptions ): Node | Image {
const options = optionize<RasterizedOptions, RasterizedOptions>()( {
resolution: 1,
sourceBounds: null,
Expand Down Expand Up @@ -165,7 +170,7 @@ export const rasterized = ( node: Node, providedOptions?: RasterizedOptions ): N
}

return returnNode.mutate( options.nodeOptions );
};
}

/**
* Calls the callback with an Image Node that contains this Node's subtree's visual form. This is always
Expand Down

0 comments on commit 0ce4d1e

Please sign in to comment.