Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

set-optional.d.ts 1.0KB

12345678910111213141516171819202122232425262728293031323334
  1. import {Except} from './except';
  2. /**
  3. Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
  4. Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
  5. @example
  6. ```
  7. import {SetOptional} from 'type-fest';
  8. type Foo = {
  9. a: number;
  10. b?: string;
  11. c: boolean;
  12. }
  13. type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
  14. // type SomeOptional = {
  15. // a: number;
  16. // b?: string; // Was already optional and still is.
  17. // c?: boolean; // Is now optional.
  18. // }
  19. ```
  20. */
  21. export type SetOptional<BaseType, Keys extends keyof BaseType = keyof BaseType> =
  22. // Pick just the keys that are not optional from the base type.
  23. Except<BaseType, Keys> &
  24. // Pick the keys that should be optional from the base type and make them optional.
  25. Partial<Pick<BaseType, Keys>> extends
  26. // If `InferredType` extends the previous, then for each key, use the inferred type key.
  27. infer InferredType
  28. ? {[KeyType in keyof InferredType]: InferredType[KeyType]}
  29. : never;