- Error
- Reported by the type checker
TS2693
'{0}' only refers to a type, but is being used as a value here.
A name that only exists as a type (interface or type alias) is used as a value. Use a real value, or compare against something that exists at runtime.
What it means
Interfaces and type aliases are erased when TypeScript is compiled, so there is nothing to refer to at runtime. Using one in an expression, such as calling it or passing it to instanceof, is an error.
Example
interface User { name: string }
const u = User;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,11): error TS2693: 'User' only refers to a type, but is being used as a value here.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- If you need a runtime value, declare a class or a constant instead of (or alongside) the type.
- For runtime type checks, test the shape:
typeof x.name === "string", or use a validator.