The error you already know
In Python you reached for Optional[str] and gave it a default of None. Call greet with a name or call it with nothing, both work. One annotation carried two ideas at once, the value can be None and the caller can leave it off.
// Optional[str] became string | null on// the way across, the obvious port.function greet(name: string | null,): string {return `Hi ${name ?? "there"}`;}// In Python you left the argument off// and the default covered you.greet()Expected 1 arguments, but got 0.;
The port turned Optional into | null and let the default fall away. So name can hold null now, which is one of those two ideas, but the parameter is still required, which loses the other. The compiler counts the arguments and stops at zero.
Python folds absence and emptiness into one None. TypeScript keeps them apart. undefined is the value that was never set, and null is a value you chose to put there. The autopilot port reached for the wrong one.
greeter.ts Expected 1 arguments, but got 0.
Watch the habit become the idiom
The fix is choosing which nothing you mean and saying so in the type. The same signature crosses over twice, first on autopilot, then the way TypeScript wants it.
Step through it at your own pace. Each click is one move.
Step 1 of 4
Good Python. Each field defaults to None, so a request sets only what it needs.
@dataclass
class ChatRequest:
prompt: str
system: Optional[str] = None
stop: Optional[str] = NoneHere's what each move does.
- Start in Python, where
Optional[str] = Nonemakes a field nullable and omittable in one stroke. - Port it on autopilot and every
Optionalturns into| null, which keeps the fields required, so each request setsnullby hand. - Swap the nullable union for the optional marker, the question mark, and the field's type becomes
string | undefined, the nothing that means absent. - Build a request with only the fields you mean. The ones you skip are
undefined, exactly the Python default you started with.
There is an honest exception. Some interfaces really do hand you null on purpose, JSON that carries an explicit null, a DOM call that returns null when nothing matched. Reach for null when you mean a value deliberately set to nothing, and reach for the optional marker when you mean a value that was never there. The rule is to know which nothing you mean.
Now make the compiler agree
Here is that request type again, ported the null-everywhere way. Turn system and stop into optional fields, then fix the request that builds them so it sets only what it means to. The compiler wants the absent nothing here, so the nullable union has to go.