Typescriptの型解決でハマった
まずこんなへなちょこコードを書いた。
import * as f1 from "./sample.ts";
const GaluchatApiJs:typeof f1={
...f1
}as typeof f1;
window.onload = function() {
var mp=new GaluchatApiJs.WebApiMapProvider("ma1000");
var cmp=new GaluchatApiJs.MapComponent(document.getElementById("main")!,mp);
cmp.update(134.72,35.6);
cmp.addEventListener('click',(e:Event)=>{
if(e instanceof GaluchatApiJs.MapMouseEvent){ //OK
}
const event = e as GaluchatApiJs.MapMouseEvent; //ERROR
console.log("クリック位置:", event.lonlat.lon, event.lonlat.lat)}
);
console.log("e");
//var img=new GaluchatApiJs.WebApiMapProvider();
// img.getMap(134.72,35.6,100,100,100).then();
}わけあってsample.jsの中にあるクラスをGaluchatApiJsに展開したつもりなのだが、instanceofはともかくasの部分がエラーになる。
chatGPTさんに聞くと、型名の解決で型としてGaluchatApiJsが認識されていないことであった。
色々試してみたが、結局のところasは使えないということで落ち着いた。悲しみ。