2
的工會是否有可能進行類型檢查函數參數是interface
的關鍵之一:打字稿蔓延`interface`鍵作爲字符串
export interface IUser {
id: string;
email: string;
password: string;
}
const updateUserProperty = (property: 'id' | 'email' | 'password') => e =>
this.setState({ [property]: e.target.value });
我想'id' | 'email' | 'password'
不被硬編碼。
以JS方式例如。 IUser
是一個對象,我可以把這一對Object.keys(IUser).join(' | ')
完美。可用,因爲:TypeScript 2.1 – dmnsgn