The error you already know
In Python a class is callable. You write Greeter("Katie") and you get an instance, no ceremony. Ported straight across, the same line stalls. TypeScript keeps the constructor behind a keyword, so it reads your call as an attempt to run the class like a plain function and says so.
class Greeter {constructor(private name: string) {}greet() {return `Hello, ${this.name}`;}}// The Python reflex, call it like// a function with no new.const hi = GreeterValue of type 'typeof Greeter' is not callable. Did you mean to include 'new'?("Katie").greet();
The quick fix is four characters, add new. But look at the class before you reach for it. One field set in the constructor, one method that reads it. On this runtime that shape is a function.
greeter.ts(11,12) Value of type 'typeof Greeter' is not callable. Did you mean to include 'new'?
Watch the habit become the idiom
Start by noticing what this particular class is doing. It holds one value and exposes one behavior that reads it. On this runtime a function already does that, and the value it closes over plays the part of the field.
Step through it at your own pace. Each click is one move.
Step 1 of 4
Good Python. One field, one method that reads it.
class Summarizer:
def __init__(self, model):
self.model = model
def run(self, text):
return call_llm(self.model, text)Here's what each move does.
- Start where Python left you, a class holding one value with one method that uses it.
- Drop the constructor. The value becomes a plain parameter the function closes over.
- Return an object literal whose method does the work. That object is the instance you used to
new. - Name the returned shape with a type. That type is all callers depend on.
Classes still earn their place. A client that holds a connection and mutates over time, an error subclass you throw and catch, a framework like NestJS that asks for them, all real reasons to write class. The tell is narrower. A constructor that only stores its arguments, paired with one method that reads them, sitting where a function would have done.
Keep one rule in your pocket. A class at your API boundary is worth a pause, but tucked behind a function it rarely is. When the only state is set once and read back, a function returning a typed object says the same thing with less to learn.
Now make the compiler agree
Here is a one-method class with a constructor, the exact tell. Refactor Translator into a type that names the returned shape and a makeTranslator function that returns it. Same behavior, no class keyword. The hidden checks only read the shape, so name the rest how you like.