Error when trying to use `pick` utility on a Struct constructed with `Describe` utility function
See original GitHub issueHi @ianstormtaylor, I followed your suggestion here https://github.com/ianstormtaylor/superstruct/issues/526#issuecomment-733209466 and everything works Ok except when I tried to use pick<Struct, ['field-1', 'field-2', ... , 'field-x']>
where the Struct
is defined using the Describe
type utility function that helps to ensure that structs match types. For example, the following:
type User = {
id: number
name: string
age: number
address: string
}
const User: Describe<User> = object({
id: number(),
name: string(),
age: number(),
address: string()
})
const basicDetails = pick<User, ['name', 'age']>
will throw the error Argument of type 'Describe<User>' is not assignable to parameter of type 'Struct<{ [x: string]: any; }, Record<string, Struct<any, any>>>'
. But if I remove : Describe<User>
then it works Ok as expected.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
ios - Do you usually use class or struct to define a list of utility ...
I think a conversation about this has to start with an understanding of dependancy injection, what it is and what problem it solves....
Read more >DataCamp_-_Track_-_Data_Scientist_with_R_-_Course_02_ ...
This chapter introduces you to a bunch of useful functions for data structure manipulation, regular expressions and working with times and dates. <div...
Read more >Generate Shared Utility Code - MATLAB & Simulink - MathWorks
The code generator verifies that the current model that you are building has configuration properties that match the checksum of properties from the...
Read more >Documentation - Utility Types - TypeScript
This type is meant to model operations like await in async functions, or the .then() method on Promise s - specifically, the way...
Read more >Utility functions | BigQuery - Google Cloud
GENERATE_UUID · Description. Returns a random universally unique identifier (UUID) as a STRING . The returned STRING consists of 32 hexadecimal digits in...
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 FreeTop 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
Top GitHub Comments
Thanks @ianstormtaylor, you’re patient and helpful.
@nwaughachukwuma I don’t think you’re using the
pick
utility correctly, at least based on that snippet. The<...>
brackets are for typings, not for runtime values. You likely want:Notice the
(...)
parentheses instead. (And you need to importpick
as well.)If you were looking to use the typing-level utility that’s built in to TypeScript, you’d do:
Notice
<...>
, uppercasePick
, and no need to import it. And this would be creating a newtype
not a struct or other runtime value.I realize the difference between compile-time typings and runtime values can often be confusing, I get tripped up on that every once in a while too. That’s the mental model complexity cost paid to have things named the same, which has other benefits.