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 LiteralToPrimitiveDeep Type #584

Merged
merged 11 commits into from Apr 4, 2023

Conversation

alvis
Copy link
Contributor

@alvis alvis commented Mar 29, 2023

This PR introduces a new utility type called LiteralToPrimitiveDeep, which aims to simplify the handling of data from a json file.

For example, if you want to pass a tsconfig to a function expecting a TsConfigJSON type, then you have to either import the expected type and cast the data to it, or simply cast the data to any.

/* function.ts */
import type { TsConfigJson } from 'type-fest';

export function doSomethingWithTSConfig(config: LiteralToPrimitiveDeep<TsConfigJson>) { ... }

/* another.ts */
import tsconfig from 'path/to/tsconfig.json';

// no casting is needed to pass the type check
doSomethingWithTSConfig(tsconfig);

// if LiteralToPrimitiveDeep is not used, you need to cast the imported data like this: 
doSomethingWithTSConfig(tsconfig as TsConfigJson);
doSomethingWithTSConfig(tsconfig as any);

readme.md Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

Thanks for contributing. Make sure you adhere to https://github.com/sindresorhus/type-fest/blob/main/.github/contributing.md

@alvis
Copy link
Contributor Author

alvis commented Mar 31, 2023

@sindresorhus Sorry for missed the code style. They are corrected.

readme.md Outdated Show resolved Hide resolved
source/literal-to-primitive-deep.d.ts Outdated Show resolved Hide resolved
source/literal-to-primitive-deep.d.ts Outdated Show resolved Hide resolved
@alfiomy
Copy link

alfiomy commented Apr 2, 2023

تمام

@alvis
Copy link
Contributor Author

alvis commented Apr 3, 2023

@sindresorhus Documentation should be much clearer now :)

@sindresorhus sindresorhus merged commit 5374588 into sindresorhus:main Apr 4, 2023
7 checks passed
@sindresorhus
Copy link
Owner

Thanks :)

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