-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Schema type declaration #121
Comments
types auto generated by typescript |
Hello, I see. Are there any plans for standalone types support, e.g. using DefinitelyTyped same way as loader-utils? My current project using schema-utils looks like: import * as schemaUtils from "schema-utils";
import { Schema, ValidationErrorConfiguration as SchemaValidationErrorConfiguration } from "schema-utils/declarations/validate";
// copied from: https://github.com/webpack/schema-utils/blob/master/declarations/validate.d.ts#L35
// this could / should be defined as its own type and be imported as above and therefore preventing breaking changes in future
type SchemaOptions = Array<object> | object;
const OPTIONS_SCHEMA: Schema = { /* ... */ };
/* ... */
const options: SchemaOptions & LoaderOptions = Object.assign({}, DEFAULT_OPTIONS, loaderOptions);
const schemaConfiguration: SchemaValidationErrorConfiguration = { name: PACKAGE_NAME, baseDataPath: "options" };
schemaUtils.validate(OPTIONS_SCHEMA, options, schemaConfiguration); Which is kinda cumberstone and imported / defined types are not namespaced in Thanks. |
We already provide types
Where? Using:
is normal, it is part of public API Again, we don't write types, it generates by typescript |
Hello,
Provided types are in different declaration file instead of
In provided example.
Same response as first one.
I understand and I don't want to argue, so if there are no plans for this, then feel free to close this issue. Thanks. |
Why do not install |
Hello, why use another package, if you already got defined possible I'm not familiar with generating types from javascript files, therefore I could not suggest solution different than write declarations manually. Thanks. |
In theory we can export |
Hello, this was my initial idea. If you include Cleanest solution from my perspective would be using same approach as loader-utils as I suggested here. Unfortunately, it requires write declarations manually. We can let this issue open for now, so more devs can suggest different / better solution. Thanks. |
I didn't really understand this issue, but I think I'm having the same problem Why is the schema 3 possible JSONSchema? The JSONSchema4 is outdated and will not trigger typescript errors if you create an invalid ajv schema An example const schema: Schema = {
properties: {
test: {
type: "boolean",
required: true, // This is a valid value according to JSONSchema4 but not JSONSchema6 and JSONSchema7
}
}
} Which when validating it on runtime will trigger a schema error Shouldn't we use the ajv JSONSchemaType exported type instead |
Yeah, it was implemented in the such way because |
I'll probably make a PR when ajv-validator/ajv#2180 is resolved currently TS is too strict and requires a complete rewrite of the schema which will turn it into a big breaking change |
Feature Proposal
Please add standalone
Schema
type declaration.Currently is possible to import it manually from validate method type declarations, but it is not convenient:
Feature Use Case
To use typed schema object, that is passed into validate method.
The text was updated successfully, but these errors were encountered: