Skip to content

Commit

Permalink
feat: set item's license setting nullable (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT authored May 23, 2024
1 parent ced27c3 commit 2009888
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/item/itemSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
OldCCLicenseAdaptations,
} from '@/enums/ccLicenses.js';
import { DescriptionPlacementType } from '@/enums/descriptionPlacement.js';
import { Nullable } from '@/typeUtils.js';

export interface ItemSettings {
/** @deprecated use item.lang */
Expand All @@ -15,10 +16,12 @@ export interface ItemSettings {
enableSaveActions?: boolean;
tags?: string[];
displayCoEditors?: boolean;
ccLicenseAdaption?:
// allow null to delete setting in the backend
ccLicenseAdaption?: Nullable<
| `${CCLicenseAdaptions}`
| CCLicenseAdaptions
// TODO: these are the old licenses, we might remove them at some point.
| `${OldCCLicenseAdaptations}`;
| `${OldCCLicenseAdaptations}`
>;
descriptionPlacement?: DescriptionPlacementType;
}
18 changes: 16 additions & 2 deletions src/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,23 @@ export type AnyOf<T> = {
[K in keyof T]: Pick<T, K>;
}[keyof T];

// TODO: add usage informations

/**
* This allow to define a type with at least one attribute of T that is not a key in E.
*
* The following type add usage informations about:
* `type ShortLinkPatchPayload = AnyOfExcept<ShortLinkPostPayload, 'itemId'>;`
* - The `itemId` is not allowed.
* - All other attributes of ShortLinkPostPayload are allowed and optional.
* - At least of attribute is required.
*/
export type AnyOfExcept<T, E extends keyof T> = AnyOf<Omit<T, E>>;

/**
* The type is T or null.
*
* - `type NullableString = Nullable<string>`:
* - `const nullableString: NullableString<string> = "my string";`
* - `const nullableString: NullableString<string> = null;`
* - `type NullableMultipleType = Nullable<string | boolean | number>`:
*/
export type Nullable<T> = T | null;

0 comments on commit 2009888

Please sign in to comment.