简体   繁体   中英

Recursive mapped types in Typescript

I don't know if this is possible but I'm wondering if you can create recursively mapped types. I don't know if that makes sense so let me try to explain what I'm trying to do.

I'm creating an excel parser that takes in workbook and returns a type T . One of the things I want to do is create a mapped typed that maps every key to a string which will correspond to an excel cell reference in the form of a string (eg 'A5' ).

I can map every key to a string like so:

{[P in keyof T]: string}

but this maps complex types (objects and arrays) to strings too but I'd actually like to map the keys of those complex values to a string too.

Any ideas?


Edit: I'm starting to think it's not possible because something like this would need to be implemented .

you couldn t before but you can now from Typescript 4.1 version. conditional recursive types are now supported

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM