Home > Blockchain >  io-ts: only refers to a type, but is being used as a value here
io-ts: only refers to a type, but is being used as a value here

Time:10-20

I'm very new to TypeScript and faced the following problem.

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
})

What's wrong with the code? How to fix that?

CodePudding user response:

In your code you are not declaring the type of testTypeV but making a variable assignment - the compiler is complaining that you are trying to assign the value of the key test to a type. Instead you need a value of type Test, for instance:

export const testTypeV = t.type({ test: { s: 'any-string' } });

The type of testTypeV is whatever is returned by t.type.

  • Related