Skip to content
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

Return previous schema type #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

klaseca
Copy link
Contributor

@klaseca klaseca commented Dec 24, 2022

Checklist

Description:

As discussed in #138, env-schema should support fluent-json-schema library out-of-the-box (without explicitly calling valueOf method). Given this requirement, we cannot use a narrower type for schema (reasons why we cannot use code from fluent-json-schema are described in #137)

In future, if we remove this requirement, it will be possible to return a more strict type

export type EnvSchemaOpt<T = EnvSchemaData> = {
schema?: JSONSchemaType<T> | AnySchema;
export type EnvSchemaOpt = {
schema?: object;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you evaluate adding the fluent-schema's JSONSchema type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite sure what you mean by that. Are you suggesting to add JSONSchema type from fluent-json-schema to union type for schema? If so, read description of this pull request

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. object is not a very good type. Should use something like Record<string, any> or so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to be honest i dont understand why we remove the generic type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is not compatible to different JSON schema library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should read backstory of this pull request - #134 , #137 , #138 . I think it will become clear to you

As for typescript:
Record<string, any> and object are equal. Also, we can not use Record<string, unknown> type, because it will not work with interfaces (typescript playground)

@Eomm Eomm requested a review from Uzlopak February 6, 2023 21:17
const optWithSchemaFluent: EnvSchemaOpt = {
schema: schemaFluent,
};
expectType<EnvSchemaOpt>(optWithSchemaFluent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it can never be false, because you cast it to EnvSchemaOpt in line 50.

@Fdawgs
Copy link
Member

Fdawgs commented Aug 12, 2023

@klaseca Any thoughts on review comments?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really convinced this is a good idea. It seems it worsen the API surface.

@climba03003
Copy link
Member

climba03003 commented Aug 13, 2023

The PR is long enough to forget the detail on why it happen.
The raise of this PR is that the current types is too strict to support only limited amount of library (only ajv).
#138

Even fluent-json-schema cannot be directly supported.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Fdawgs Fdawgs requested review from Uzlopak and Eomm August 13, 2023 08:28
@klaseca
Copy link
Contributor Author

klaseca commented Aug 13, 2023

The PR is long enough to forget the detail on why it happen. The raise of this PR is that the current types is too strict to support only limited amount of library (only ajv). #138

Even fluent-json-schema cannot be directly supported.

Not exactly. Not only ajv is supported. We have tests for typebox, and they work. Only problem is desire to pass fluent-json-schema schemas without explicitly calling valueOf

@Eomm Eomm removed their request for review October 30, 2023 16:53
@Fdawgs Fdawgs requested a review from a team January 27, 2024 08:23
@jsumners
Copy link
Member

attn: @fastify/typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants