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 types: nullable and defined return any #1253

Closed
mdismer opened this issue Feb 10, 2021 · 5 comments · Fixed by #1256
Closed

Typescript types: nullable and defined return any #1253

mdismer opened this issue Feb 10, 2021 · 5 comments · Fixed by #1256

Comments

@mdismer
Copy link

mdismer commented Feb 10, 2021

Describe the bug

nullable() and defined() on object and array schema return any.

Expected behavior

Both functions return the correct type (ObjectSchema / ArraySchema)

Platform:

  • Version 0.32.8
@Bartmr
Copy link

Bartmr commented Feb 10, 2021

This can be anything: a miss-type, conflicting declarations, a value that cannot be inferred.

Can you give a use-case?

@mdismer
Copy link
Author

mdismer commented Feb 11, 2021

Yes here is a simple example:

import * as yup from 'yup'

interface Foo {
  test: string
}

interface Bar {
  foo: Foo | null
  foos: Foo[] | null
}

const fooSchema: yup.SchemaOf<Foo> = yup.object({
  test: yup.string().defined()
})

const barSchema: yup.SchemaOf<Bar> = yup.object({
  foo: fooSchema.defined().nullable(),
  foos: yup.array().of(fooSchema.defined()).defined().nullable()
})

Both fooSchema.defined() and array().of(fooSchema) return any

Happens which pretty much any object schema.

@bart-opplane
Copy link
Contributor

Opened pull request #1256 to fix this for arrays

@mdismer
Copy link
Author

mdismer commented Feb 16, 2021

@bart-opplane Thanks for the pull request. Do you have an idea how to fix it for objects?

@Bartmr
Copy link

Bartmr commented Feb 16, 2021

@mdismer It's me, @bart-opplane , but from my personal account. No idea. To be honest, the typings in this library are super confusing.

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.

3 participants