我有一個可以輸出字串或未定義值的函式。我目前已將任一輸出與 | 操作員。這是正確的,還是有更好的方法?
export function retrievePath(specFile: any): string | undefined{
// ...
};
uj5u.com熱心網友回復:
這是正確的。
以另一種方式,您可以定義 a typeof string | undefined。
type PathType = string | undefined;
export function retrievePath(specFile: any): PathType {
// ...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/508372.html
標籤:打字稿
下一篇:輸入'可觀察的<true|undefined>'不能分配給angularauthguard實作上的型別'Observable<boolean>
