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

New Type "RequiredByValueExcept<T, ValueType>", "PartialByValueExcept<T, ValueType>" #173

Open
black7375 opened this issue Oct 15, 2021 · 0 comments

Comments

@black7375
Copy link

black7375 commented Oct 15, 2021

Is your feature request related to a real problem or use-case?

This is useful when defining parameter values ​​for functions.

Describe a solution including usage in code example

interface optionI {
  inputPath: string;
  outputPath: string;
  format: string;
}

const defaultOption: RequiredByValueExcept<optionI, 'inputPath' | 'outputPath'> = {
  format: 'txt'
};

function foo(text: string, option: PartialByValueExcept<optionI, 'inputPath' | 'format'>) {
  // ...
}

Who does this impact? Who is this for?

I think this would be useful for defining default values ​​and parameters.

Describe alternatives you've considered (optional)

Additional context (optional)

The naming convention has been unified.
https://stackoverflow.com/questions/52703321/make-some-properties-optional-in-a-typescript-type

type RequiredByValueExcept<T, TOptional extends keyof T> = Pick<T, Diff<keyof T, TOptional>> & Partial<T>;
type PartialByValueExcept<T, TRequired extends keyof T> = Partial<T> & Pick<T, TRequired>;
@black7375 black7375 changed the title New Type "RequiredByValueExcept<T, ValueType>", "OptionalByValueExcept<T, ValueType>" New Type "RequiredByValueExcept<T, ValueType>", "PartialByValueExcept<T, ValueType>" Oct 15, 2021
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

No branches or pull requests

1 participant