creationFunction in ProviderViewModel mistype

Hi,
I’ve had to update my cesium from 1.85 to 1.107.2 recently and I had to change how we load our tiles into our viewer and it “works”(while it is inconsistent with node 16 vs node 18) but I can’t yarn build my project due to a type error.
I’m passing the same imageryProvider as before and that creationFunction still expects Cesium.ProviderViewModel.CreationFunction | Cesium.Command

Error

Type '() => Promise<Cesium.TileMapServiceImageryProvider>' is not assignable to type 'CreationFunction | Command'.
  Type '() => Promise<Cesium.TileMapServiceImageryProvider>' is not assignable to type 'CreationFunction'.
    Type 'Promise<TileMapServiceImageryProvider>' is not assignable to type 'ImageryProvider | TerrainProvider | ImageryProvider[] | TerrainProvider[] | Promise<TerrainProvider> | Promise<...>'.
      Type 'Promise<TileMapServiceImageryProvider>' is not assignable to type 'Promise<TerrainProvider>'.
        Type 'TileMapServiceImageryProvider' is missing the following properties from type 'TerrainProvider': hasWaterMask, hasVertexNormals, availability, requestTileGeometry, and 3 more.ts(2322)
Cesium.d.ts(42875, 9): The expected type comes from property 'creationFunction' which is declared here on type '{ name: string; tooltip: string

Old code that used to work with 1.85:

      const imageryProvider = new Cesium.TileMapServiceImageryProvider({
        url: Cesium.buildModuleUrl("../assets/world_imagery"),
        fileExtension: "jpg",
        maximumLevel: 9,
      });
      const providerViewModel = new Cesium.ProviderViewModel({
        name: "Fake Imagery",
        tooltip: "Fake images",
        iconUrl: Cesium.buildModuleUrl("../assets/0/0/0.jpg"),
        category: "Other",
        creationFunction: () => imageryProvider,
      });

Changed it for 1.107.2 with the new syntax:

      const imageryProvider = Cesium.TileMapServiceImageryProvider.fromUrl(
        Cesium.buildModuleUrl("../assets/world_imagery"),
        {
          fileExtension: "jpg",
          maximumLevel: 9,
        }
      );

      const providerViewModel = new Cesium.ProviderViewModel({
        name: "Fake Imagery",
        tooltip: "Fake images",
        iconUrl: Cesium.buildModuleUrl("../assets//0/0/0.jpg"),
        category: "Other",
        creationFunction: () => imageryProvider,
      });

Any help is greatly appreciated!!

1 Like

I think the typings are wrong (by Cesium).

CreationFunction is defined as:

type CreationFunction = () => ImageryProvider | TerrainProvider | ImageryProvider[] | TerrainProvider[] | Promise<TerrainProvider> | Promise<TerrainProvider[]>;

So it’s missing the type Promise<ImageryProvider>. You can try cast your imageryProvider as any. Does this help?

Since this is bugging me too, I created an issue on github. Feel free to follow there.

1 Like