我在打字稿中将一个对象转换为另一种类型。但是返回的对象具有原始对象的属性。我想获得OutputInterface
的格式,而不是InputInterface
的格式。
export interface InputInterface {
username: string;
createdAt: number;
active: boolean;
roles: any;
}
export interface OutputInterface {
username: string;
active: number;
roles: any;
}
const i: InputInterface = {
username: "username",
createdAt: 1,
active: true,
roles: []
};
const converted = (i as unknown) as OutputInterface;
console.log("final value", converted);
// final value { username: 'username', createdAt: 1, active: true, roles: [] }