从生成的类型实例中选择一些属性不起作用,为什么?
Pick some properties from generated Instance of type is not working, why?
正在尝试生成一个只有一些属性的新类型,但我一无所获..
const User = types.model({
id: types.identifier,
username: types.maybe(types.string),
email: types.maybe(types.string),
});
type TUser = Instance<typeof User>;
type TDatabaseUser = Pick<TUser, 'id' | 'email'>
TDatabaseUser has no properties.. and should have id
and email
我做错了什么?
您的代码似乎按预期工作。
import { Instance, types } from "mobx-state-tree";
const User = types.model({
id: types.identifier,
username: types.maybe(types.string),
email: types.maybe(types.string)
});
type TUser = Instance<typeof User>;
type TDatabaseUser = Pick<TUser, "id" | "email">;
const dbUser: TDatabaseUser = {
id: "1",
email: "test@test.com",
// id and email works, but username gives rise to an error.
username: "does not work"
};
正在尝试生成一个只有一些属性的新类型,但我一无所获..
const User = types.model({
id: types.identifier,
username: types.maybe(types.string),
email: types.maybe(types.string),
});
type TUser = Instance<typeof User>;
type TDatabaseUser = Pick<TUser, 'id' | 'email'>
TDatabaseUser has no properties.. and should have
id
and
我做错了什么?
您的代码似乎按预期工作。
import { Instance, types } from "mobx-state-tree";
const User = types.model({
id: types.identifier,
username: types.maybe(types.string),
email: types.maybe(types.string)
});
type TUser = Instance<typeof User>;
type TDatabaseUser = Pick<TUser, "id" | "email">;
const dbUser: TDatabaseUser = {
id: "1",
email: "test@test.com",
// id and email works, but username gives rise to an error.
username: "does not work"
};