Skip to content

'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 new with an interface or type alias

  • Using a type name in a runtime expression

  • Confusing a type with a class

  • Trying to use instanceof with an interface

Minimal example

✗ Broken code
interface Person { name: string; }
const p = new Person(); // Person is a type, not a constructor
✓ Fixed code
class 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 interface or type (not class)

  • 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 class instead of interface

  • If 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

Related Resources

Related Glossary

← Back to language