我正在尝试使用 .json 文件填充一些函数参数,但是当我尝试在 Near 协议中构建合同时,命令窗口返回错误 TS6054。我正在从同一个目录导入 .json 并使用“import * as data from ../contract/assembly/sensor_data.json” 我已经修改了 tsconfig.json 并包含了 compileOperations: "resolveJsonModule": true,"esModuleInterop":真的。但这仍在继续发生。我还能做什么?
这是我的代码:
import { PersistentSet, PersistentUnorderedMap } from "near-sdk-as";
import * as data from '../../contract/assembly/sensor_data.json';
@nearBindgen
export class Sensor {
sensorName: string;
sensorType: string;
ownerId: string;
allowedUsers: PersistentSet<string>;
userRequests: PersistentSet<string>;
constructor(
_ownerId: string,
_sensorName: string,
_sensorType: string,) {
this.ownerId = _ownerId;
this.sensorName = _sensorName;
this.sensorType = _sensorType;
this.allowedUsers = new PersistentSet<string>(this.sensorName + "A");
this.userRequests = new PersistentSet<string>(this.sensorName + "U");
}
getArgs(): string {
return "{}";
}
hasAccess(accountId: string): bool {
return this.allowedUsers.has(accountId) || accountId == this.ownerId;
}
getRequests(): string {
let array: Array<string> = this.userRequests.values();
return array.join(",");
}
addRequest(accountId: string): void {
this.userRequests.add(accountId);
}
}
export class DHT11 extends Sensor{
id : number;
date: string;
temp: f32;
hum : f32
constructor(
sensorName:string,
sensorType:string,
ownerId:string,
_id : number,
_date:string,
_temp:f32,
_hum: f32){
super(sensorName,sensorType,ownerId)
let n= 1
for (n ; n < data.Data.length; n++) {
const DHT11 = data.Data[n];
this.id = DHT11.id;
this.date = DHT11.date;
this.temp = DHT11.temperature;
this.hum = DHT11.humidity;
}
}
getArgs(): string {
return "{Dispositivo DHT11. Sensor que mide temperatura y humedad}";
}
getState(): string {
return "{id:" + this.id.toString() + ", Date:"
+ this.date.toString() + ", Temperature:" + this.temp.toString()
+ ", Humidity:" + this.hum.toString() + "}";
}
}
export let sensorRegistry = new PersistentUnorderedMap<string, Sensor>("s");
export let DHT11Registry = new PersistentUnordered
地图<string, DHT11>("d");