javascript - 如何在 TypeScript 中導出類型,它把類型標記為未定義
我需要將我的 types 放在一個單獨的檔案中,在那裡我創建它並將其作為預設輸出,像這樣:
type props = {
playerId: string;
isAutoplayPrevented: boolean;
}
// 'props' is not defined.eslint(no-undef)
export default props;
雖然我已經定義了 props,但我仍然收到 ESLint 警告說 props 是 undefined。我是否應該忽略這個警告並停止 ESLint 的抱怨,像這樣:// eslint-disable-next-line no-undef
或者有其他更合適的解決方案嗎?
答案#1
我建議你考慮將類型放在一個獨立的文件中,並像下面這樣編寫類型:
export type General = {
classes: Record<string, string>,
};
export type AxiosCall = {
// etc
};
// etc
對於使用,你可以輕鬆地在其他元件中 導入 它。
