Why is Object
overwritten?
#1236
-
from this code: https://github.com/sinclairzx81/typebox/blob/master/src/type/object/object.ts#L94-L101 by using var here, the runtime Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@tylersayshi Hi,
This // Babel Polyfill Header
Object.defineProperty(....) // <--- 'Object used before initialization error here
// TypeBox export
export const Object = _Object // <--- Because Object is defined as 'const' here There were two solutions available.
I went with the latter option as it wasn't really feasible for Babel to use As for the The declaration of Object is largely an annoying bit of trivia TypeBox carries around and unfortunately, there are too many downstream tools that hang various logic off the non-qualified Object. TypeBox doesn't really have option other than to fudge the declaration, but certainly would be open to alternative way to declare, particularly for such a critical type. Hope this brings some insight |
Beta Was this translation helpful? Give feedback.
@tylersayshi Hi,
This
Object
declaration is both intentional and unfortunate. The reason Object is defined this way is due Babel transforms not qualifyingglobalThis.Object
in the module header polyfill. There were issues related to "Object used before initialization" when TypeBox declared the Object withconst
. The following is the high level summary.