記事の命名が迷子
やりたいこと
こういったオブジェクトがあって、
interface UserProperties {
userid: number;
username: string;
}
const getUserProperties = (): UserProperties => ({
userid: 1,
username: 'おなまえ',
});
別のオブジェクトの引数なんかにに代入したい
class User {
id: number;
name: string;
constructor(params: { id: number; name: string }) {
this.name = params.name;
this.id = params.id;
}
}
変数を定義してから
const props = getUserProperties();
const user = new User({ id: props.userid, name: props.username });
定義せずに
const user = new User(
((props: UserProperties) => ({
id: props.userid,
name: props.username,
}))(getUserProperties()),
);
定義せずに書くと
読みにくい