我對 TypeScript 很陌生,遇到了以下問題。
import * as t from "io-ts";
interface Test {
s: string
}
export const testTypeV = t.type({
test: Test //Error: 'Test' only refers to a type, but is being used as a value here
})
代碼有什么問題?如何解決?
uj5u.com熱心網友回復:
在您的代碼中,您不是在宣告型別,testTypeV而是在進行變數賦值 - 編譯器抱怨您試圖將鍵的值分配給test型別。相反,您需要一個 type 值Test,例如:
export const testTypeV = t.type({ test: { s: 'any-string' } });
的型別testTypeV是 回傳的任何內容t.type。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/326534.html
上一篇:打字稿鍵入帶有資料的物件鍵
