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
anneg
August 4, 2023, 9:46am
2
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?
anneg
August 4, 2023, 11:55am
3
Since this is bugging me too, I created an issue on github. Feel free to follow there.
opened 11:54AM - 04 Aug 23 UTC
closed 06:55PM - 08 Aug 23 UTC
type - bug
The [`CreationFunction`](https://cesium.com/learn/cesiumjs/ref-doc/ProviderViewM… odel.html?classFilter=providerviewmo#.CreationFunction) is missing some types. The current definition is:
```
ImageryProvider|TerrainProvider|Array.<ImageryProvider>|Array.<TerrainProvider>|Promise.<TerrainProvider>|Promise.<Array.<TerrainProvider>>
```
However, I was recently updating to Version 1.106 where the imagery providers need to be created using `fromURL`.
Before, I could do this:
```ts
const providerViewModels = [] as Cesium.ProviderViewModel[];
providerViewModels.push(new Cesium.ProviderViewModel({
name: 'Bing Maps Aerial',
iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/bingAerial.png'),
tooltip: 'Bing Maps aerial imagery \nhttp://www.bing.com/maps',
creationFunction: () => new Cesium.BingMapsImageryProvider({
url: 'https://dev.virtualearth.net',
key: bingMapsKey,
mapStyle: Cesium.BingMapsStyle.AERIAL,
}),
}));
```
Now this is not possible anymore, since the `BingMapsImageryProvider` constructor should not be used anymore. Instead, according to the docs, we need to use `from Url`.
```ts
providerViewModels.push(new Cesium.ProviderViewModel({
name: 'Bing Maps Aerial',
iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/bingAerial.png'),
tooltip: 'Bing Maps aerial imagery \nhttp://www.bing.com/maps',
creationFunction: function() {
return Cesium.BingMapsImageryProvider.fromUrl(
'https://dev.virtualearth.net',
{
key: bingMapsKey,
mapStyle: Cesium.BingMapsStyle.AERIAL,
},
) as any; // as any, because `Promise<ImageryProvider>` is not part of the `CreationFunction` type definition
},
}));
```
Note the `as any`. If I don't put it there, I get the error below. To me, it looks like the `CreationFunction` type definition is just missing the `Promise<ImageryProvider>` (and `Promise<ImageryProvider[]>` I suppose). Is it missing for a certain purpose, or was it forgotten?
I have this problem and found that [someone else on the community forum](https://community.cesium.com/t/creationfunction-in-providerviewmodel-mistype/25884/1) has the same issue.
```
Type '() => Promise<BingMapsImageryProvider>' is not assignable to type 'CreationFunction | Command'.
Type '() => Promise<BingMapsImageryProvider>' is not assignable to type 'CreationFunction'.
Type 'Promise<BingMapsImageryProvider>' is not assignable to type 'TerrainProvider | ImageryProvider | ImageryProvider[] | TerrainProvider[] | Promise<TerrainProvider> | Promise<...>'.
Type 'Promise<BingMapsImageryProvider>' is not assignable to type 'Promise<TerrainProvider>'.
Type 'BingMapsImageryProvider' is missing the following properties from type 'TerrainProvider': hasWaterMask, hasVertexNormals, availability, requestTileGeometry, and 3 more.ts(2322)
Cesium.d.ts(43996, 9): The expected type comes from property 'creationFunction' which is declared here on type '{ name: string; tooltip: string; iconUrl: string; category?: string; creationFunction: CreationFunction | Command; }'
```
1 Like