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

Template type improvements #380

Merged
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
4 changes: 2 additions & 2 deletions dev/manifest-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {parseJson} from './json.js';
const dirname = path.dirname(fileURLToPath(import.meta.url));

/**
* @template T
* @template [T=unknown]
* @param {T} value
* @returns {T}
*/
Expand Down Expand Up @@ -240,7 +240,7 @@ export class ManifestUtil {
}

/**
* @template T
* @template [T=unknown]
* @param {T[]} array1
* @param {T[]} array2
* @param {number} lengthOffset
Expand Down
2 changes: 1 addition & 1 deletion ext/js/comm/frame-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class FrameClient {
}

/**
* @template T
* @template [T=unknown]
* @param {T} data
* @returns {import('frame-client').Message<T>}
* @throws {Error}
Expand Down
6 changes: 3 additions & 3 deletions ext/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function stringReverse(string) {

/**
* Creates a deep clone of an object or value. This is similar to `parseJson(JSON.stringify(value))`.
* @template T
* @template [T=unknown]
* @param {T} value The value to clone.
* @returns {T} A new clone of the value.
* @throws An error if the value is circular and cannot be cloned.
Expand Down Expand Up @@ -245,7 +245,7 @@ export function generateId(length) {

/**
* Creates an unresolved promise that can be resolved later, outside the promise's executor function.
* @template T
* @template [T=unknown]
* @returns {import('core').DeferredPromiseDetails<T>} An object `{promise, resolve, reject}`, containing the promise and the resolve/reject functions.
*/
export function deferPromise() {
Expand Down Expand Up @@ -514,7 +514,7 @@ export class EventListenerCollection {
/**
* Class representing a generic value with an override stack.
* Changes can be observed by listening to the 'change' event.
* @template T
* @template [T=unknown]
* @augments EventDispatcher<import('dynamic-property').EventType>
*/
export class DynamicProperty extends EventDispatcher {
Expand Down
6 changes: 3 additions & 3 deletions ext/js/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class Database {
}

/**
* @template TPredicateArg
* @template [TPredicateArg=unknown]
* @template [TResult=unknown]
* @template [TResultDefault=unknown]
* @param {TObjectStoreName} objectStoreName
Expand All @@ -174,8 +174,8 @@ export class Database {
}

/**
* @template TData
* @template TPredicateArg
* @template [TData=unknown]
* @template [TPredicateArg=unknown]
* @template [TResult=unknown]
* @template [TResultDefault=unknown]
* @param {IDBObjectStore|IDBIndex} objectStoreOrIndex
Expand Down
2 changes: 1 addition & 1 deletion ext/js/data/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class JsonSchema {
}

/**
* @template T
* @template [T=unknown]
* @param {T} value
* @returns {T}
*/
Expand Down
2 changes: 1 addition & 1 deletion ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ export class DisplayGenerator {
}

/**
* @template TItem
* @template [TItem=unknown]
* @template [TExtraArg=void]
* @param {HTMLElement} container
* @param {(item: TItem, arg: TExtraArg) => ?Node} createItem
Expand Down
2 changes: 1 addition & 1 deletion ext/js/dom/selector-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* Class which is used to observe elements matching a selector in specific element.
* @template T
* @template [T=unknown]
*/
export class SelectorObserver {
/**
Expand Down
3 changes: 2 additions & 1 deletion ext/js/general/cache-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@


/**
* @template K,V
* @template [K=unknown]
* @template [V=unknown]
* Class which caches a map of values, keeping the most recently accessed values.
*/
export class CacheMap {
Expand Down
3 changes: 2 additions & 1 deletion ext/js/general/task-accumulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import {log} from '../core.js';

/**
* @template K,V
* @template [K=unknown]
* @template [V=unknown]
*/
export class TaskAccumulator {
/**
Expand Down
2 changes: 1 addition & 1 deletion ext/js/language/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ export class Translator {
// Miscellaneous

/**
* @template T
* @template [T=unknown]
* @param {Set<T>} set
* @param {T[]} values
* @returns {boolean}
Expand Down
2 changes: 1 addition & 1 deletion ext/js/pages/settings/keyboard-mouse-input-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class KeyboardMouseInputField extends EventDispatcher {
}

/**
* @template T
* @template [T=unknown]
* @param {T[]} array1
* @param {T[]} array2
* @returns {boolean}
Expand Down
2 changes: 1 addition & 1 deletion ext/js/pages/settings/profile-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export class ProfileController {
}

/**
* @template T
* @template [T=unknown]
* @param {T} currentValue
* @param {T} value1
* @param {T} value2
Expand Down
2 changes: 1 addition & 1 deletion test/json-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function createProxy(schema, value) {
}

/**
* @template T
* @template [T=unknown]
* @param {T} value
* @returns {T}
*/
Expand Down
2 changes: 1 addition & 1 deletion types/ext/anki-templates-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type CreateDetails = {
media?: AnkiTemplates.Media;
};

export type CachedValue<T> = {
export type CachedValue<T = unknown> = {
getter: () => T;
hasValue: boolean;
value: T | undefined;
Expand Down
2 changes: 1 addition & 1 deletion types/ext/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type * as Translator from './translator';

// Generic

export type Handler<TDetails, TResult, THasSender extends boolean = false> = (
export type Handler<TDetails = unknown, TResult = unknown, THasSender extends boolean = false> = (
details: TDetails,
sender: (THasSender extends true ? chrome.runtime.MessageSender : void)
) => (TResult | Promise<TResult>);
Expand Down
2 changes: 1 addition & 1 deletion types/ext/cache-map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

export type Node<K, V> = {
export type Node<K = unknown, V = unknown> = {
key: K | null;
value: V | null;
previous: Node<K, V> | null;
Expand Down
2 changes: 1 addition & 1 deletion types/ext/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type TokenString = string;

export type TokenObject = Record<string, never>;

export type DeferredPromiseDetails<T> = {
export type DeferredPromiseDetails<T = unknown> = {
promise: Promise<T>;
resolve: (value: T) => void;
reject: (reason?: RejectionReason) => void;
Expand Down
2 changes: 1 addition & 1 deletion types/ext/dictionary-data-util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type KanjiFrequenciesMap2Data = {

export type TermFrequenciesMap3 = Map<string, FrequencyData>;

export type DictionaryFrequency<T> = {
export type DictionaryFrequency<T = unknown> = {
dictionary: string;
frequencies: T[];
};
Expand Down
6 changes: 3 additions & 3 deletions types/ext/dictionary-database.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ export type FindMultiBulkData<TItem = unknown> = {
indexIndex: number;
};

export type CreateQuery<TItem> = (item: TItem) => (IDBValidKey | IDBKeyRange | null);
export type CreateQuery<TItem = unknown> = (item: TItem) => (IDBValidKey | IDBKeyRange | null);

export type FindPredicate<TItem, TRow> = (row: TRow, item: TItem) => boolean;
export type FindPredicate<TItem = unknown, TRow = unknown> = (row: TRow, item: TItem) => boolean;

export type CreateResult<TItem, TRow, TResult> = (row: TRow, data: FindMultiBulkData<TItem>) => TResult;
export type CreateResult<TItem = unknown, TRow = unknown, TResult = unknown> = (row: TRow, data: FindMultiBulkData<TItem>) => TResult;

export type DictionarySet = {
has(value: string): boolean;
Expand Down
6 changes: 3 additions & 3 deletions types/ext/dictionary-worker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type InvokeDetails<TResponseRaw = unknown, TResponse = unknown> = {
formatResult: ((result: TResponseRaw) => TResponse) | null;
};

export type MessageCompleteData<TResponseRaw> = {
export type MessageCompleteData<TResponseRaw = unknown> = {
action: 'complete';
params: MessageCompleteParams<TResponseRaw>;
};
Expand All @@ -44,7 +44,7 @@ export type MessageGetImageDetailsData = {
params: MessageGetImageDetailsParams;
};

export type MessageCompleteParams<TResponseRaw> = Core.Response<TResponseRaw>;
export type MessageCompleteParams<TResponseRaw = unknown> = Core.Response<TResponseRaw>;

export type MessageProgressParams = {
args: unknown[];
Expand All @@ -56,7 +56,7 @@ export type MessageGetImageDetailsParams = {
mediaType: string;
};

export type MessageData<TResponseRaw> = MessageCompleteData<TResponseRaw> | MessageProgressData | MessageGetImageDetailsData;
export type MessageData<TResponseRaw = unknown> = MessageCompleteData<TResponseRaw> | MessageProgressData | MessageGetImageDetailsData;

export type MessageCompleteResultSerialized = {
result: DictionaryImporter.Summary;
Expand Down
24 changes: 12 additions & 12 deletions types/ext/dom-data-binder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@

import type * as TaskAccumulator from './task-accumulator';

export type CreateElementMetadataCallback<T> = (element: Element) => T | undefined;
export type CreateElementMetadataCallback<T = unknown> = (element: Element) => T | undefined;

export type CompareElementMetadataCallback<T> = (metadata1: T, metadata2: T) => boolean;
export type CompareElementMetadataCallback<T = unknown> = (metadata1: T, metadata2: T) => boolean;

export type GetValuesCallback<T> = (args: GetValuesDetails<T>[]) => Promise<TaskResult[]>;
export type GetValuesCallback<T = unknown> = (args: GetValuesDetails<T>[]) => Promise<TaskResult[]>;

export type SetValuesCallback<T> = (args: SetValuesDetails<T>[]) => Promise<TaskResult[]>;
export type SetValuesCallback<T = unknown> = (args: SetValuesDetails<T>[]) => Promise<TaskResult[]>;

export type GetValuesDetails<T> = {
export type GetValuesDetails<T = unknown> = {
element: Element;
metadata: T;
};

export type SetValuesDetails<T> = {
export type SetValuesDetails<T = unknown> = {
element: Element;
metadata: T;
value: ValueType;
};

export type OnErrorCallback<T> = (error: Error, stale: boolean, element: Element, metadata: T) => void;
export type OnErrorCallback<T = unknown> = (error: Error, stale: boolean, element: Element, metadata: T) => void;

export type ConstructorDetails<T> = {
export type ConstructorDetails<T = unknown> = {
selector: string;
createElementMetadata: CreateElementMetadataCallback<T>;
compareElementMetadata: CompareElementMetadataCallback<T>;
Expand All @@ -47,7 +47,7 @@ export type ConstructorDetails<T> = {
onError?: OnErrorCallback<T> | null;
};

export type ElementObserver<T> = {
export type ElementObserver<T = unknown> = {
element: Element;
type: NormalizedElementType;
value: unknown;
Expand All @@ -70,17 +70,17 @@ export type AssignTaskValue = {value: ValueType};

export type ValueType = boolean | string | number | null;

export type UpdateTask<T> = [
export type UpdateTask<T = unknown> = [
key: ElementObserver<T> | null,
task: TaskAccumulator.Task<UpdateTaskValue>,
];

export type AssignTask<T> = [
export type AssignTask<T = unknown> = [
key: ElementObserver<T> | null,
task: TaskAccumulator.Task<AssignTaskValue>,
];

export type ApplyTarget<T> = [
export type ApplyTarget<T = unknown> = [
observer: ElementObserver<T>,
task: TaskAccumulator.Task<UpdateTaskValue> | TaskAccumulator.Task<AssignTaskValue> | null,
];
Expand Down
2 changes: 1 addition & 1 deletion types/ext/dynamic-property.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

export type EventType = 'change';

export type ChangeEventDetails<T> = {
export type ChangeEventDetails<T = unknown> = {
value: T;
};
12 changes: 6 additions & 6 deletions types/ext/selector-observer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

export type OnAddedCallback<T> = (element: Element) => T | undefined;
export type OnAddedCallback<T = unknown> = (element: Element) => T | undefined;

export type OnRemovedCallback<T> = (element: Element, data: T) => void;
export type OnRemovedCallback<T = unknown> = (element: Element, data: T) => void;

export type OnChildrenUpdatedCallback<T> = (element: Element, data: T) => void;
export type OnChildrenUpdatedCallback<T = unknown> = (element: Element, data: T) => void;

export type IsStaleCallback<T> = (element: Element, data: T) => boolean;
export type IsStaleCallback<T = unknown> = (element: Element, data: T) => boolean;

export type ConstructorDetails<T> = {
export type ConstructorDetails<T = unknown> = {
/** A string CSS selector used to find elements. */
selector: string;
/** A string CSS selector used to filter elements, or `null` for no filtering. */
Expand All @@ -48,7 +48,7 @@ export type MutationRecordLike = {
target: Node;
};

export type Observer<T> = {
export type Observer<T = unknown> = {
element: Element;
ancestors: Node[];
data: T;
Expand Down
2 changes: 1 addition & 1 deletion types/ext/task-accumulator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

export type Task<V> = {
export type Task<V = unknown> = {
data: V;
stale: boolean;
};