Skip to content
New issue

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

Add DeepFlattenRecord type (and helpers) #571

Closed
wants to merge 1 commit into from

Conversation

dwheale
Copy link

@dwheale dwheale commented Mar 12, 2023

I know the preference is to submit one type per PR but the other types are required for DeepFlattenRecord to work. I found that an API I was pulling from provided data in a nested format, which I needed flattened.

@tommy-mitchell
Copy link
Contributor

What are all the types that have been added? It would probably help to add them to the PR description. Do all of them need to be exposed, or can some be internal / part of deep-flatten-record.d.ts?

I think the convention is that Deep types have the label added to the suffix, not prefix (i.e. FlattenRecordDeep).


type ExampleType = {
arrayKey: string[];
objectKey: {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tab-indentation.

@param {{ cascadeOptionality?: boolean }} Options The options to use when flattening
@example
```
import type { DeepFlattenRecord } from 'type-fest';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import type { DeepFlattenRecord } from 'type-fest';
import type {DeepFlattenRecord} from 'type-fest';


This is useful when you have a nested object that you want to use as a form or table schema, but you want to flatten it into a single object.

@param BaseType The type to flatten
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@param BaseType The type to flatten
@param BaseType - The type to flatten.

/**
Deeply flattens a Record type recursively. If a key is an object, it will be flattened into the parent object.
By default, if a key containing an object is optional,the object will be flattened into the parent object and all
it's keys will be optional. This can be disabled by setting `cascadeOptionality` in `DeepFlattenOptions` to `false`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hard-wrap.

Comment on lines +12 to +15
/**
Whether to cascade optionality on an object (e.g. if a parent is optional, all children will be as well regardless of their original optionality)
@default true
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
Whether to cascade optionality on an object (e.g. if a parent is optional, all children will be as well regardless of their original optionality)
@default true
*/
/**
Whether to cascade optionality on an object (e.g. if a parent is optional, all children will be as well regardless of their original optionality)
@default true
*/

@sindresorhus
Copy link
Owner

Bump

@sindresorhus
Copy link
Owner

Closing for lack of response: #633

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants