typescript - React-Native undefined 无法解析模块
问题描述
我正在尝试导入我在打字稿中制作的类,并将其初始化为与我的视图组件一起传递。但是当我尝试初始化类时,出现以下错误:
我的导入如下所示:
import GameModel from 'src/Rematch/Models/GameModel';
我的 GameModel 类如下所示:
import { QuestionModel } from "./QuestionModel";
export default class GameModel {
public questions: QuestionModel[] = [];
constructor(private id: number = 0) {
this.getData(id);
}
getData(id: number) {
console.log(id);
this.questions.push(new QuestionModel(['Goed', 'Fout', 'Nog fouter'], 'Goed', 'Dit is de eerste vraag. Als je deze goed hebt krijg je punten'));
this.questions.push(new QuestionModel(['Fout', 'Goed', 'Foutig'], 'Goed', 'Dit is de tweede vraag. Als je deze goed hebt krijg je punten'));
this.questions.push(new QuestionModel(['Fout', 'Fouter dan fout', 'Goed'], 'Goed', 'Dit is de derde vraag. Als je deze goed hebt krijg je punten'));
this.questions.push(new QuestionModel(['Dit is ook fout', 'Goed', 'Fout'], 'Goed', 'Dit is de vierde vraag. Als je deze goed hebt krijg je punten'))
}
}
打字时:
const game: GameModel = new GameModel(1)
出现错误
解决方案
您的导入必须与您编写的文档相关,因此应该是这样的:
import GameModel from './Rematch/Models/GameModel';
推荐阅读
- swift - 在文档中生成超过 58 个 PDF 页面时应用程序终止(内存问题?)Swift
- laravel - 雄辩地查询与嵌套 WHERE 的关系
- python - PyTest:如果满足某个条件,如何跳过当前目录下的所有测试?
- c++ - 错误:构造函数必须显式初始化引用成员
- javascript - 使用纯js从参数创建嵌套哈希?
- xml - Odoo 13 如何从代码中使用 Html 小部件编辑字段?
- python - Torch:训练后如何检查重量?
- mongodb - 在 ubuntu wsl2 systemd 上安装 MongoDB 问题 systemd 作为 init 系统(PID 1)
- pandas - 如果列表中的一个值有分号,我如何展平列表中的值?
- kubernetes - 如何通过 kubespray 设置本地主机名通过身份验证?