'X' only refers to a type, but is being used as a value here
Error message
only refers to a type, but is being used as a value here
Quick summary
You used a type or interface name in a value position (e.g., with `new` or as a variable), but types are erased at compile time and have no runtime existence.
Why this happens
Using
newwith an interface or type aliasUsing a type name in a runtime expression
Confusing a type with a class
Trying to use
instanceofwith an interface
Minimal example
interface Person { name: string; }
const p = new Person(); // Person is a type, not a constructorclass Person { constructor(public name: string) {} }
const p = new Person("Alice");Use a class instead of an interface when you need a constructor.
How to diagnose
Check if the name is declared as
interfaceortype(notclass)Determine if you need a runtime value or just a type
Look for
new,instanceof, or other value-position usages
How to fix
If you need a constructor, use a
classinstead ofinterfaceIf you need an object, use an object literal:
const x: MyType = { ... }If you need instanceof, use a class or a custom type guard
If you need a runtime check, write a type guard function
How to prevent
Understand that types are compile-time only (type erasure)
Use classes when you need both types and runtime behavior