@mittwald/react-ghostmaker 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { expectTypeOf, test } from "vitest";
2
2
  import { ProjectGhost } from "./testMocks.js";
3
+ import { asGhost } from "./maybeGhost/asGhost.js";
3
4
  test("return type is correct", () => {
4
5
  const customerNameGhost = ProjectGhost.ofId("Project A")
5
6
  .getDetailed()
@@ -23,3 +24,19 @@ test("transform return type is correct", () => {
23
24
  .name.transform(() => 0);
24
25
  expectTypeOf(transformedToNumber).toEqualTypeOf();
25
26
  });
27
+ test("asGhost() works with generics", () => {
28
+ class A {
29
+ foo() {
30
+ //
31
+ }
32
+ }
33
+ class B {
34
+ foo() {
35
+ //
36
+ }
37
+ }
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
+ function generic(prop) {
40
+ asGhost(prop).foo().use();
41
+ }
42
+ });
@@ -20,8 +20,9 @@ export interface ReactGhostMethods<T> extends Promise<T> {
20
20
  }
21
21
  export declare const transformFnProp: "___transformFn";
22
22
  export declare const isGhostMarker: "___ghostMarker";
23
+ type GhostProp<V, TOriginal> = V extends AnyFunction ? (...args: Parameters<V>) => ReactGhost<Awaited<ReturnType<V>> | OrOptional<TOriginal>> : ReactGhost<V | OrOptional<TOriginal>>;
23
24
  export type ReactGhost<T> = ReactGhostMethods<T> & {
24
- [K in keyof NonNullable<T>]-?: NonNullable<T>[K] extends AnyFunction ? <TParams extends Parameters<NonNullable<T>[K]>>(...args: TParams) => ReactGhost<Awaited<ReturnType<NonNullable<T>[K]>> | OrOptional<T>> : ReactGhost<NonNullable<T>[K] | OrOptional<T>>;
25
+ [K in keyof NonNullable<T>]-?: GhostProp<NonNullable<T>[K], T>;
25
26
  };
26
27
  export interface GhostChainItem {
27
28
  propName: string | typeof transformFnProp;
@@ -42,3 +43,4 @@ export interface UseGhostReturn<T> {
42
43
  }
43
44
  export declare function isReactGhost<T>(something: unknown): something is ReactGhost<T>;
44
45
  export type ModelIdentifier = (model: unknown) => string | undefined;
46
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-ghostmaker",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
5
5
  "contributors": [
6
6
  "Marco Falkenberg <m.falkenberg@mittwald.de>"