-
Notifications
You must be signed in to change notification settings - Fork 90
Description
Importing "Object" from runtypes while also using ES decorators causes runtime failures like:
Exception during run: TypeError: Object.getOwnPropertyDescriptor is not a function
To make it work, I find I have to rename Object on import:
import {
// Work around
Object as Dictionary,
type Parsed,
String,
} from 'runtypes';
const LoginRequest = Dictionary({
username: String,
password: String,
});
export class TestController extends ControllerBase {
@Post('/login')
static login(req: Request): Response {
return req.password == 'foo';
}
}The Post decorator (source not shown) doesn't use Object directly. But TypeScript emits a helper function called __esDecorate that uses Object.getOwnPropertyDescriptor internally. But the runtype Object import masks the global Object.
This isn't an issue if I use decorators and runtypes in separate modules, but I'm not far enough into the project to know if I would still have this issue if I start bundling everything into a single file.
Arguably, TypeScript should generate code that references globalThis.Object.getOwnPropertyDescriptor instead. In the mean time, maybe this should get a mention in the README, so people know they may need to rename Object to avoid clobbering the global one?
If I can make a minimal repro for a TypeScript bug report, I'll link to it here.