请教一下,如何只增加.d.ts

引擎3.3版本后,请问如果增加.d.ts文件,没有对应的.js文件, .js文件会由打包时(或者是平台打入),根据不同平台要不要增加,或者增加不同的。
但现在引擎代码只要有.d.ts文件,就会报错。

// TestPlatform.d.ts
declare class TestPlatform {
    public a: number;
    public f1(a: number): void;
}


export const testPlatform: TestPlatform;
// 调用声名代码
testPlatform?.f1(3);

无法从 file:///D:/Workspace/workspace/CarCraftIO/assets/scripts/GameView.ts 解析出模块 ./TestPlatform,已将其视为外部模块。

这是因为:Error: 以 file:///D:/Workspace/workspace/CarCraftIO/assets/scripts/GameView.ts 为起点找不到模块 "./TestPlatform"

问题出在这里吧。。。

你的脚本导入了这里导出的常量,这显然是不行的。

再说你这 3.3 的项目是用 ts 写的吧?为啥还要自己写 d.ts?

我把export 写成declare也不行。
自己写d.ts有几种作用,一是可以接外部SDK,比喻某个平台的SDK,只提供了types文件,真正js代码只有上传了他们平台才有。或者说像微信小游戏,自己写个wx.d.ts,就可以在开发时有代码提示作用了呀。

declare class TestPlatform {
  public a: number;
  public f1(a: number): void;
}

interface Window {
  platform: TestPlatform;
}

你那sdk应该是挂在全局变量上吧

我目前也是这样的思路写平台接口.d.ts,也出现"以xxx为起点找不到模块"的问题,请问楼主最后是怎么解决的?

export declare const testPlatform: TestPlatform

平台模块化不就好了,游戏内调一个入口文件,这个文件内部自行处理对应平台的广告代码image