File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed
Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -71,26 +71,29 @@ Coming from `express-jsonschema`? Read the [migration notes](docs/migrating-from
7171
7272### Schemas in TypeScript
7373
74- If you are writing JSON schemas in TypeScript, you will need to cast your schema
75- to the ` const ` type e.g.
74+ If you're writing JSON schemas in TypeScript, you'll need to use the
75+ ` AllowedSchema ` type e.g.
7676
7777``` typescript
78- const addressSchema = {
78+ import { AllowedSchema } from " express-json-validator-middleware" ;
79+
80+ const addressSchema: AllowedSchema = {
7981 type: " object" ,
8082 required: [" street" ],
8183 properties: {
8284 street: {
8385 type: " string" ,
8486 }
8587 },
86- } as const ;
88+ };
8789```
8890
89- This is required so that TypeScript doesn't attempt to widen the types of values
90- in the schema object. If you omit the ` as const ` statement TypeScript will raise
91- a compilation error. The discussion in
92- [ this issue] ( https://github.com/simonplend/express-json-validator-middleware/issues/39 )
93- provides further background.
91+ This is required so TypeScript doesn't attempt to widen the types of values
92+ in the schema object. If you omit this type, TypeScript will raise an error.
93+
94+ See issues [ #39 ] ( https://github.com/simonplend/express-json-validator-middleware/issues/39 )
95+ and [ #102 ] ( https://github.com/simonplend/express-json-validator-middleware/issues/102 )
96+ for more background.
9497
9598## Error handling
9699
You can’t perform that action at this time.
0 commit comments