这可能是一个愚蠢的问题,但为什么我得到一个"意想不到的令牌"以下代码段的错误?请记住,它是一个猫鼬模型。
错误消息
SyntaxError: D:/Coding/Species Project/backend/models/species.js: Unexpected token (15:2)
13 | },
14 | organism: {
> 15 | ...shared,
| ^
16 | enum: ["Plant", "Animal", "Other"],
17 | },
18 | taxonomy: {
猫鼬模型
const shared = {
type: String,
required: true,
}
const SpeciesSchema = new Schema({
name: {
common: shared,
scientific: shared,
},
organism: {
...shared,
enum: ["Plant", "Animal", "Other"],
},
...,
}
答案 0 :(得分:1)
Spread运算符用作数组的参数。
你可能想要使用它,而不是
const SpeciesSchema = new Schema({
name: {
common: shared,
scientific: shared,
},
organism: Object.assign({}, shared, enum: ["Plant", "Animal", "Other"]},
...,
}