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

feat: set item's license setting nullable #525

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;