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

Typescript: SchemaDescription no longer exported #1144

Closed
martnst opened this issue Dec 4, 2020 · 4 comments · Fixed by #1748
Closed

Typescript: SchemaDescription no longer exported #1144

martnst opened this issue Dec 4, 2020 · 4 comments · Fixed by #1748

Comments

@martnst
Copy link

martnst commented Dec 4, 2020

Describe the bug
It appears that e.g.SchemaDescription are no longer exported.

Is this on purpose? The README on the other hand still lists it here.
So it seems to not just be an internal type.

To Reproduce

import { SchemaDescription } from 'yup/lib/schema'

export function envConfigFromSchemaDescription(schemaDescription: SchemaDescription): any {
  // …
}

Expected behavior
It should not be required to be importing from internal lib folder whatsoever.

import { SchemaDescription } from 'yup'

Platform (please complete the following information):

$  yarn list | grep yup
├─ @types/yup@0.26.37
└─ yup@0.32.1
@jquense
Copy link
Owner

jquense commented Dec 4, 2020

happy to take PR that exports it. lots of types probably are missing that are worth exporting!

@calumjames
Copy link

calumjames commented Apr 7, 2022

@jquense, this issue is a couple of years old, but these types seem to be importable in the latest stable Yup but not importable in the latest Yup beta. Would I be okay to repurpose this issue to fix it in the Yup beta, or should this issue be closed and a new one for the beta problem created?

@jquense
Copy link
Owner

jquense commented Apr 11, 2022

yeah go for it 👍 this is issue is fine to hijack

@Branden97
Copy link

Branden97 commented Aug 16, 2022

For anyone looking for a quick way to get these types in the beta version, this is how I did it:

import * as yup from 'yup'

// The beta version of yup doesn't export these types, so we have to extract them ourselves...
export type SchemaFieldDescription = ValueOf<ReturnType<yup.AnyObjectSchema['describe']>['fields']>
export type SchemaRefDescription = Extract<SchemaFieldDescription, { type: 'ref' }>
export type SchemaInnerTypeDescription = Extract<SchemaFieldDescription, { innerType?: SchemaFieldDescription }>
export type SchemaObjectDescription = Extract<SchemaFieldDescription, { fields: Record<string, SchemaFieldDescription> }>
export type SchemaDescription = Exclude<Exclude<Extract<SchemaFieldDescription, { optional: boolean }>, { innerType?: SchemaFieldDescription }>, { fields: Record<string, SchemaFieldDescription> }>

export type Reference = Extract<ValueOf<yup.AnyObjectSchema['fields']>, { __isYupRef: boolean }>```

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 a pull request may close this issue.

4 participants