查找: 不正确类型导入
找错误 中等
题目
这个 code 有类型错误. 查找 mistake:
代码
import { Person } from "./types";
const p = new Person();
提示
类型 and 接口 don't exist at 运行时. 能你 use '新' 使用它们?
解释
If Person is an interface or type alias (not a class), it cannot be used with new — types are erased at compile time and have no runtime existence. TypeScript errors: 'Person' only refers to a type, but is being used as a value here. Fix: if Person is a type, create an object literal: const p: Person = { ... }. If you need a constructor, use a class.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。