We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please follow the template and fill the info. A PR will be auto-generated and always reflect on your changes. Detailed solution/guide is not required, but please be sure the challenge is solvable.
Please follow the template and fill the info. A PR will be auto-generated and always reflect on your changes.
Detailed solution/guide is not required, but please be sure the challenge is solvable.
difficulty: easy # hard title: Overwrtie type with type of child # tags: union, array # separate by comma
Assuming you have and object of type
{ "id": number, "foo": { "id": number, "data": { "id": number, "prop1": any, "prop2": any } } }
and we want to remove the nesting of the data to get a type
{ "id": number, "foo": { "id": number, "prop1": any, "prop2": any } }
Should also work with deeper levels of nesting e.g.
interface DeepModel { 'id': number, 'foo': { 'id': number, 'data': { 'id': number, 'prop1': any, 'prop2': any, 'bar': { 'id': number, 'data': { 'id': number, 'prop1': any, 'prop2': any, } } } } }
should be reduced to
interface ReducedDeepModel { 'id': number, 'foo': { 'id': number, 'prop1': any, 'prop2': any, 'bar': { 'id': number, 'prop1': any, 'prop2': any, } } }
type ReducedNesting<T> = any
import type { Equal, Expect } from '@type-challenges/utils' interface Model { "id": number, "extension": { "id": number, "data": { "id": number, "prop1": any, "prop2": any } } } type ReducedModel = { "id": number, "extension": { "id": number, "prop1": any, "prop2": any } } interface DeepModel { 'id': number, 'foo': { 'id': number, 'data': { 'id': number, 'prop1': any, 'prop2': any, 'bar': { 'id': number, 'data': { 'id': number, 'prop1': any, 'prop2': any, } } } } } interface ReducedDeepModel { 'id': number, 'foo': { 'id': number, 'prop1': any, 'prop2': any, 'bar': { 'id': number, 'prop1': any, 'prop2': any, } } } type cases = [ Expect<Equal<ObjectFromEntries<ReducedModel>, Model>>, Expect<Equal<ObjectFromEntries<DeepModel>, ReducedDeepModel>>, ]
typescript playground
PS: sorry I did not figure out how I can make the template as beautiful as the others, but I hope this is an interesting challenge
The text was updated successfully, but these errors were encountered:
#20745 - Pull Request updated.
Sorry, something went wrong.
feat(question): add #20744 - Overwrtie type with type of child
ca41d1e
5c5bc12
Successfully merging a pull request may close this issue.
Info
Question
Assuming you have and object of type
and we want to remove the nesting of the data to get a type
Should also work with deeper levels of nesting e.g.
should be reduced to
Template
Test Cases
typescript playground
PS: sorry I did not figure out how I can make the template as beautiful as the others, but I hope this is an interesting challenge
The text was updated successfully, but these errors were encountered: