TypeScript: oneOf should accept readonly array
See original GitHub issueDescribe the bug
When handing in a readonly array to yup.mixed().oneOf, there is a TypeScript error:
The type ‘readonly ["pass", "fail", "any"]’ is ‘readonly’ and cannot be assigned to the mutable type any[]
To Reproduce
const validOptions = ["pass", "fail", "any"] as const
const schema = yup.mixed().oneOf(validOptions)
Expected behavior
The type should be adjusted to readonly any[]
in order to indicate that the array doesn’t have to be mutable.
Platform (please complete the following information):
- TypeScript 3.9.5
- Yup 0.32.9
Additional context
I have not tested this with TypeScript 4.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:15
- Comments:6
Top Results From Across the Web
Enforce readonly array parameter for using the values of one ...
Specifically, I want to pass an array of objects to a function and its second parameter is the value of one of the...
Read more >Read-Only Array and Tuple Types in TypeScript - Marius Schulz
The intersperse function accepts an array of elements of some type T and a separator value of the same type T . It...
Read more >ReadonlyArray Lesson - Execute Program
Learn programming tools like JavaScript, TypeScript, SQL, and regular expressions fast. Interactive lessons with real code examples.
Read more >Understanding and Embracing TypeScript's “readonly”
Understanding this lesson allows us to do things like efficiently assembling objects and arrays in mutable space inside a function–while ...
Read more >Why you'll love Typescript's ReadonlyArray - Reddit
If a method accepts a read-only array, then it can't be sure that it won't be modified somewhere else. If it wants to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can also do:
(so you don’t need to define the values twice)
What is this closed? I’m on 0.32.11 and still facing this issue.