Prechádzať zdrojové kódy

fix: return type signatures for JSR

Sv443 3 mesiacov pred
rodič
commit
c782a4965d
4 zmenil súbory, kde vykonal 22 pridanie a 18 odobranie
  1. 1 1
      jsr.json
  2. 9 9
      lib/Debouncer.ts
  3. 11 8
      lib/translation.ts
  4. 1 0
      package.json

+ 1 - 1
jsr.json

@@ -10,7 +10,7 @@
       "dist/index.cjs",
       "dist/index.global.js",
       "dist/index.umd.js",
-      "dist/lib/**/*.d.ts",
+      "dist/lib/**/*",
       "package.json",
       "README-summary.md",
       "CHANGELOG.md",

+ 9 - 9
lib/Debouncer.ts

@@ -61,54 +61,54 @@ export class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArgs>> {
   //#region listeners
 
   /** Adds a listener function that will be called on timeout */
-  public addListener(fn: DebouncerFunc<TArgs>) {
+  public addListener(fn: DebouncerFunc<TArgs>): void {
     this.listeners.push(fn);
   }
 
   /** Removes the listener with the specified function reference */
-  public removeListener(fn: DebouncerFunc<TArgs>) {
+  public removeListener(fn: DebouncerFunc<TArgs>): void {
     const idx = this.listeners.findIndex((l) => l === fn);
     idx !== -1 && this.listeners.splice(idx, 1);
   }
 
   /** Removes all listeners */
-  public removeAllListeners() {
+  public removeAllListeners(): void {
     this.listeners = [];
   }
 
   //#region timeout
 
   /** Sets the timeout for the debouncer */
-  public setTimeout(timeout: number) {
+  public setTimeout(timeout: number): void {
     this.emit("change", this.timeout = timeout, this.type);
   }
 
   /** Returns the current timeout */
-  public getTimeout() {
+  public getTimeout(): number {
     return this.timeout;
   }
 
   /** Whether the timeout is currently active, meaning any latest call to the {@linkcode call()} method will be queued */
-  public isTimeoutActive() {
+  public isTimeoutActive(): boolean {
     return typeof this.activeTimeout !== "undefined";
   }
 
   //#region type
 
   /** Sets the edge type for the debouncer */
-  public setType(type: DebouncerType) {
+  public setType(type: DebouncerType): void {
     this.emit("change", this.timeout, this.type = type);
   }
 
   /** Returns the current edge type */
-  public getType() {
+  public getType(): DebouncerType {
     return this.type;
   }
 
   //#region call
 
   /** Use this to call the debouncer with the specified arguments that will be passed to all listener functions registered with {@linkcode addListener()} */
-  public call(...args: TArgs[]) {
+  public call(...args: TArgs[]): void {
     /** When called, calls all registered listeners */
     const cl = (...a: TArgs[]) => {
       this.queuedCall = undefined;

+ 11 - 8
lib/translation.ts

@@ -178,7 +178,7 @@ function trFor<TTrKey extends string = string>(language: string, key: TTrKey, ..
  * t("hello", "John"); // "Hello, John!"
  * ```
  */
-function useTr<TTrKey extends string = string>(language: string) {
+function useTr<TTrKey extends string = string>(language: string): (key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) => ReturnType<typeof trFor<TTrKey>> {
   return (key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) =>
     translate<TTrKey>(language, key, ...args);
 }
@@ -350,7 +350,7 @@ function deleteTransform(patternOrFn: RegExp | string | TransformFn): boolean {
  * t("greeting", { user: "John" }); // "Hello, John!\nYou have ${notifs} notifications."
  * ```
  */
-const templateLiteralTransform = [
+const templateLiteralTransform: TransformTuple<string> = [
   /\$\{([a-zA-Z0-9$_-]+)\}/gm,
   ({ matches, trArgs, trValue }) => {
     const patternStart = "${",
@@ -392,7 +392,7 @@ const templateLiteralTransform = [
 
     return str;
   },
-] as const satisfies TransformTuple<string>;
+] as const;
 
 /**
  * This transform will replace `%n` placeholders with the value of the passed arguments.  
@@ -414,7 +414,7 @@ const templateLiteralTransform = [
 * t("greeting", "John"); // "Hello, John!\nYou have %2 notifications."
 * ```
 */
-const percentTransform = [
+const percentTransform: TransformTuple<string> = [
   /\$\{([a-zA-Z0-9$_-]+)\}/gm,
   ({ matches, trArgs, trValue }) => {
     let str = String(trValue);
@@ -427,14 +427,17 @@ const percentTransform = [
 
     return str;
   },
-] as const satisfies TransformTuple<string>;
+] as const;
 
 //#region exports
 
 const tr = {
-  for: <TTrKey extends string = string>(...params: Parameters<typeof trFor<TTrKey>>) => trFor<TTrKey>(...params as Parameters<typeof trFor<TTrKey>>),
-  use: <TTrKey extends string = string>(...params: Parameters<typeof useTr<TTrKey>>) => useTr<TTrKey>(...params as Parameters<typeof useTr<TTrKey>>),
-  hasKey: <TTrKey extends string = string>(language = fallbackLang ?? "", key: TTrKey) => hasKey<TTrKey>(language, key),
+  for: <TTrKey extends string = string>(...params: Parameters<typeof trFor<TTrKey>>): ReturnType<typeof trFor<TTrKey>> =>
+    trFor<TTrKey>(...params as Parameters<typeof trFor<TTrKey>>),
+  use: <TTrKey extends string = string>(...params: Parameters<typeof useTr<TTrKey>>): ReturnType<typeof useTr<TTrKey>> =>
+    useTr<TTrKey>(...params as Parameters<typeof useTr<TTrKey>>),
+  hasKey: <TTrKey extends string = string>(language = fallbackLang ?? "", key: TTrKey): ReturnType<typeof hasKey<TTrKey>> =>
+    hasKey<TTrKey>(language, key),
   addTranslations,
   getTranslations,
   deleteTranslations,

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
     "update-jsr-version": "node --import tsx ./tools/update-jsr-version.mts",
     "publish-package": "changeset publish",
     "publish-package-jsr": "pnpm update-jsr-version && npx jsr publish --allow-dirty",
+    "check-jsr": "npx jsr publish --allow-dirty --dry-run",
     "change": "changeset",
     "test-serve": "node --import tsx ./test/TestPage/server.mts",
     "test-dev": "cd test/TestScript && pnpm dev",