Record with a required key
See original GitHub issueIs it possible to create a record (e.g. Record<string, Struct>
) which has one required key? I’m trying to get the equivalent of something like the this in TypeScript:
interface Type {
foo: Struct;
[key: string]: Struct;
}
I tried using an union
with object
and record
, but that results in something like
type Type = { foo: Struct; } | Record<string, Struct>;
Which results in “type ‘string’ can’t be used to index type”-like errors elsewhere. I currently solved it by using refinement
and specifying a custom type as generic parameter, but I’d like to know if there’s an easier solution to accomplish this.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Record with required keys and string index [duplicate]
keys () and trying to map to Report object, which I feel is just bad implementation. Why don't you try this for iterating...
Read more >Python - Maximum record value key in dictionary
In this, we iterate through each key for keys and assign to max, the maximum of required key in nested record.
Read more >Documentation - Utility Types - TypeScript
Record <Keys, Type>. Released: 2.1. Constructs an object type whose property keys are Keys and whose property values are Type . This utility...
Read more >How does the TypeScript Record type work? - Tim Mousk
The TypeScript Record<Keys, Type> utility type is used to construct a new type whose properties are Keys and values are Type.
Read more >Write Key Record (QC3WRTKR, Qc3WriteKeyRecord) API - IBM
Required Parameter Group. Qualified keystore file name: INPUT; CHAR(20). The keystore file where the key will be stored. The first 10 characters contain...
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
My guess is that you’re looking for something like:
That seems to work great, thanks!