Openlayers throws error by applying extent on ol.layer.Tile

I’m trying to render a tile layer on Open Street Map as an overlay layer.
When I set extent to avoid sending out-of-bound requests to the tile server, I get error tilesByZ[z] is not iterable which I don’t understand.

enter image description here

Here is my code:

/**
 * Create ol.layer.Tile
 * @param {ITileLayer} params layer parameters
 */
export const CreateTileLayer = (params: ITileLayer): TileLayer<OSM | XYZ> => {
  const layer = new TileLayer({
    source: CreateTileSource(params.id, params.url),
    properties: {
      id: params.id,
      label: params.label,
      groupId: params.groupId,
      type: params.type,
    },
    extent: params.extent,
  });
  layer.setZIndex(params.zIndex);
  layer.setVisible(params.visible);
  return layer;
};

I searched on Openlayer github issues and I found it was reported here as a bug and fixed here.

Then I tried to install the latest version ("ol": "^10.0.0") but it didn’t work.
I expected the new release fixes this issue.

Should I wait for a new release?