Comments (2)
@kevinfaveri Hi,
Is this by design?
Yeah, this is a consequence of the design. The reason this is possible is because TypeBox types extend the following open interface (which permits any
additional extra properties). TypeBox gives hints for the known additional properties (as given by the SchemaOptions
interface), but for anything else, it just trusts you.
export interface SchemaOptions {
$schema?: string
$id?: string
title?: string
description?: string
default?: any
examples?: any
readOnly?: boolean
writeOnly?: boolean
[prop: string]: any // meaning T.Optional and by extension T.Optional() (call expression) is allowed.
}
Note: The reason TypeBox uses
any
vsunknown
is largely historical. The additional properties ofany
are mostly used for property hooks in downstream tooling, so changing tounknown
has a potential to cause a lot of breakage (so reluctant to change in the near term). The ability to .chain() function calls off the end of schemas is very unfortunate though (and may look to revise things here in future)
Is there any way to enforce those wildcards / any deep field are not acceptable at build time?
Unfortunately no. Because the SchemaOptions is fully open to extension, it's very difficult to constrain without additional wrapping of the types. The appropriate solution here would be to have SchemaOptions constrain to unknown
. This would at least warn of attempted member expression / call expression on the types. But as this can't be done for other reasons, things are largely at a impasse (at least for now)
Will close off this issue for now, but hopefully the above provides some insights into why this is possible. TypeBox is getting some fairly significant internal updates done to it's inference infrastructure for the next release (scheduled sometime near the end of this year). I will mark this issue as an aspect for review ... but for now, things are working as per design.
All this best
S
from typebox.
Thanks sir!
from typebox.
Related Issues (20)
- Types for both CJS and ESM cause ambiguity and prevent correct type resolution. HOT 8
- unique id for schemas generated with Type.Object() HOT 6
- Custom paths for custom validation errors HOT 2
- Composite Union type does not work HOT 3
- Type.Recursive does not work with Type.Transform for StaticDecode
- Issue regarding nested objects when using Value.Default HOT 5
- Enum type inferred as never when using Type.Mapped() HOT 2
- Should `IsValueType` guard consider `Date`? HOT 1
- ESNext target HOT 3
- Trying to do codegen from Drizzle schemas HOT 1
- Make `default` and `examples` schema options properties type-safe HOT 2
- Indicate which files don't have "sideEffects" in package.json for improved tree shaking HOT 3
- Dynamic Template Literals can't be Mapped HOT 2
- How should TypeBox types be used with TS type predicates? HOT 2
- TypeCompiler.Compile incorrectly parsing `Record<any, any>`
- Error when using Composite with Ref (Unable to dereference schema with $id 'undefined') HOT 3
- Transform type keys in Record
- Is it possible to add support to the Type.String additional properties for the enum keyword HOT 2
- Support for async validations?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typebox.