question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type inference is broken for `array().of(...)`: union type turns into unknown

See original GitHub issue

Describe the bug

import yup from 'yup'

const alphabet = ['a', 'b', 'c'] as const
const letter = yup.mixed().oneOf(alphabet).required() // MixedSchema<"a" | "b" | "c">
const word = yup.array().of(letter) // NotRequiredArraySchema<unknown>, should be <"a" | "b" | "c"> instead of unknown

To Reproduce https://codesandbox.io/s/adoring-wing-xss7k?file=/src/index.ts

Version

@types/yup: 0.29.6
yup: 0.29.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vamshisuramcommented, Sep 3, 2020

@amankkg Hey. I am new here. Just trying to check the issue out. It seems the codesandbox is incomplete. Can you please take a look?

image

0reactions
jquensecommented, Sep 30, 2020

types aren’t maintained here currently open an Issue on DT for any type issues please

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Inference - TypeScript
The type of the x variable is inferred to be number . This kind of inference takes place when initializing variables and members,...
Read more >
Why is type inference not working on union types when one of ...
The real use case I am facing is that I get a response from some HTTP call. Right off the wire, it has...
Read more >
Announcing TypeScript 4.8 - Microsoft Developer Blogs
Today we're excited to announce the release of TypeScript 4.8! ... For example, unknown is close in spirit to the union type {}...
Read more >
TypeScript Fundamentals - Joy of Code
Since pokemon is an array the editor intellisense is smart enough to only show us array methods. ... TypeScript can infer types to...
Read more >
Python Type Checking (Guide) - Real Python
Type annotations and type hints; Adding static types to code, both your code and the code of others; Running a static type checker;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found