I was using OpenLayers 10.5.0 with Proj4 2.19.5 in a Vue3/Typescript project and this morning I upgraded those version to OL 10.6.1 and Proj4 2.19.7. Now I'm facing this typing issue:
error TS2345: Argument of type '{ (toProj: string | PROJJSONDefinition | Projection): Converter; (fromProj: string | PROJJSONDefinition | Projection, toProj: string | ... 1 more ... | Projection): Converter; <T extends TemplateCoordinates>(toProj: string | ... 1 more ... | Projection, coord: T): T; <T extends TemplateCoordinates>(fromProj: string ...' is not assignable to parameter of type 'typeof import("c:/_my_frontend/node_modules/proj4/dist/index")'.
My code was a simple usecase of adding a custom projection (key and value strings) to proj4 and registering it.
import { register } from 'ol/proj/proj4'
import proj4 from 'proj4'
const projList: { key: string; value: string }[] = [
{ key: 'EPSG:2154', value: '+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs ' },
{ key: 'EPSG:3943', value: '+proj=lcc +lat_1=42.25 +lat_2=43.75 +lat_0=43 +lon_0=3 +x_0=1700000 +y_0=2200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs ' },
]
function _handleInputProjection(projCode: string) {
const proj: { key: string; value: string } | undefined = projList.find((proj: { key: string; value: string }) => proj.key == EPSG:${projCode})
if (!proj) return
proj4.defs(proj.key, proj.value)
register(proj4)
}
It still working very nice but the build is stuck right now.
Ok, finally found out that it wasn't an OL nor Proj4 issue but an ESLint one.
register(proj4 as any)
solved this.