mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
* Use typescript-strict-plugin to iteratively turn on strict * Add strict testing to pipeline Can be executed locally through either `npm run test:types` for full type checking including spec files, or `npx tsc-strict` for only tsconfig.json included files. * turn on strict for scripts directory * Use plugin for all tsconfigs in monorepo vscode is capable of executing tsc with plugins, but uses the most relevant tsconfig to do so. If the plugin is not a part of that config, it is skipped and developers get no feedback of strict compile time issues. These updates remedy that at the cost of slightly more complex removal of the plugin when the time comes. * remove plugin from configs that extend one that already has it * Update workspace settings to honor strict plugin * Apply strict-plugin to native message test runner * Update vscode workspace to use root tsc version * `./node_modules/.bin/update-strict-comments` 🤖 This is a one-time operation. All future files should adhere to strict type checking. * Add fixme to `ts-strict-ignore` comments * `update-strict-comments` 🤖 repeated for new merge files
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { LinkedIdType } from "./enums";
|
|
import { ItemView } from "./models/view/item.view";
|
|
|
|
type LinkedMetadataAttributes = {
|
|
/**
|
|
* The i18n key used to describe the decorated class property in the UI.
|
|
* If it is null, then the name of the class property will be used as the i18n key.
|
|
*/
|
|
i18nKey?: string;
|
|
|
|
/**
|
|
* The position of the individual field to be applied when sorted.
|
|
*/
|
|
sortPosition: number;
|
|
};
|
|
|
|
export class LinkedMetadata {
|
|
private readonly _i18nKey: string;
|
|
readonly sortPosition: number;
|
|
|
|
constructor(
|
|
readonly propertyKey: string,
|
|
attributes: LinkedMetadataAttributes,
|
|
) {
|
|
this._i18nKey = attributes?.i18nKey;
|
|
this.sortPosition = attributes.sortPosition;
|
|
}
|
|
|
|
get i18nKey() {
|
|
return this._i18nKey ?? this.propertyKey;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* A decorator used to set metadata used by Linked custom fields. Apply it to a class property or getter to make it
|
|
* available as a Linked custom field option.
|
|
* @param id - A unique value that is saved in the Field model. It is used to look up the decorated class property.
|
|
* @param options - {@link LinkedMetadataAttributes}
|
|
*/
|
|
export function linkedFieldOption(id: LinkedIdType, attributes: LinkedMetadataAttributes) {
|
|
return (prototype: ItemView, propertyKey: string) => {
|
|
if (prototype.linkedFieldOptions == null) {
|
|
prototype.linkedFieldOptions = new Map<LinkedIdType, LinkedMetadata>();
|
|
}
|
|
|
|
prototype.linkedFieldOptions.set(id, new LinkedMetadata(propertyKey, attributes));
|
|
};
|
|
}
|