Skip to content

Commit

Permalink
fix(core): Improve routeAction$() type inference (#5034)
Browse files Browse the repository at this point in the history
* fix: action type

* chore: remove unnecessary exports

* fix: general case

* docs: update api

* fixup! docs: update api

---------

Co-authored-by: Miško Hevery <misko@hevery.com>
  • Loading branch information
wtlin1228 and mhevery authored Aug 28, 2023
1 parent ba71fd8 commit 2b856e3
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 208 deletions.
30 changes: 1 addition & 29 deletions packages/docs/src/routes/api/qwik-city/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,6 @@
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.actionconstructor.md"
},
{
"name": "ActionOptions",
"id": "actionoptions",
"hierarchy": [
{
"name": "ActionOptions",
"id": "actionoptions"
}
],
"kind": "Interface",
"content": "```typescript\nexport interface ActionOptions \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [id?](#) | <code>readonly</code> | string | _(Optional)_ |\n| [validation?](#) | <code>readonly</code> | DataValidator\\[\\] | _(Optional)_ |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.actionoptions.md"
},
{
"name": "ActionOptionsWithValidation",
"id": "actionoptionswithvalidation",
"hierarchy": [
{
"name": "ActionOptionsWithValidation",
"id": "actionoptionswithvalidation"
}
],
"kind": "Interface",
"content": "```typescript\nexport interface ActionOptionsWithValidation<B extends TypedDataValidator = TypedDataValidator> \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [id?](#) | <code>readonly</code> | string | _(Optional)_ |\n| [validation](#) | <code>readonly</code> | \\[val: B, ...a: DataValidator\\[\\]\\] | |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.actionoptionswithvalidation.md"
},
{
"name": "ActionStore",
"id": "actionstore",
Expand Down Expand Up @@ -348,7 +320,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type LoaderSignal<T> = T extends () => ValueOrPromise<infer B> ? ReadonlySignal<ValueOrPromise<B>> : ReadonlySignal<T>;\n```",
"content": "```typescript\nexport type LoaderSignal<TYPE> = TYPE extends () => ValueOrPromise<infer VALIDATOR> ? ReadonlySignal<ValueOrPromise<VALIDATOR>> : ReadonlySignal<TYPE>;\n```",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.loadersignal.md"
},
Expand Down
34 changes: 5 additions & 29 deletions packages/docs/src/routes/api/qwik-city/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,6 @@ export interface ActionConstructor

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts)

## ActionOptions

```typescript
export interface ActionOptions
```

| Property | Modifiers | Type | Description |
| ---------------- | --------------------- | --------------- | ------------ |
| [id?](#) | <code>readonly</code> | string | _(Optional)_ |
| [validation?](#) | <code>readonly</code> | DataValidator[] | _(Optional)_ |

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts)

## ActionOptionsWithValidation

```typescript
export interface ActionOptionsWithValidation<B extends TypedDataValidator = TypedDataValidator>
```

| Property | Modifiers | Type | Description |
| --------------- | --------------------- | ------------------------------- | ------------ |
| [id?](#) | <code>readonly</code> | string | _(Optional)_ |
| [validation](#) | <code>readonly</code> | [val: B, ...a: DataValidator[]] | |

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts)

## ActionStore

```typescript
Expand Down Expand Up @@ -350,9 +324,11 @@ export interface Loader<RETURN>
## LoaderSignal
```typescript
export type LoaderSignal<T> = T extends () => ValueOrPromise<infer B>
? ReadonlySignal<ValueOrPromise<B>>
: ReadonlySignal<T>;
export type LoaderSignal<TYPE> = TYPE extends () => ValueOrPromise<
infer VALIDATOR
>
? ReadonlySignal<ValueOrPromise<VALIDATOR>>
: ReadonlySignal<TYPE>;
```
[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts)
Expand Down
40 changes: 20 additions & 20 deletions packages/qwik-city/runtime/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,36 @@ export interface Action<RETURN, INPUT = Record<string, any>, OPTIONAL extends bo
// @public (undocumented)
export interface ActionConstructor {
// Warning: (ae-forgotten-export) The symbol "TypedDataValidator" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataValidator" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "GetValidatorType" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "StrictUnion" needs to be exported by the entry point index.d.ts
//
// (undocumented)
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: B | ActionOptionsWithValidation<B>): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>, GetValidatorType<B>, false>;
// Warning: (ae-forgotten-export) The symbol "DataValidator" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "FailOfRest" needs to be exported by the entry point index.d.ts
//
// (undocumented)
<O extends Record<string, any> | void | null, B extends TypedDataValidator, REST extends DataValidator[]>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: B, ...rest: REST): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>> | FailOfRest<REST>>, GetValidatorType<B>, false>;
<OBJ extends Record<string, any> | void | null, VALIDATOR extends TypedDataValidator, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (data: GetValidatorType<VALIDATOR>, event: RequestEventAction) => ValueOrPromise<OBJ>, options: {
readonly id?: string;
readonly validation: [VALIDATOR, ...REST];
}): Action<StrictUnion<OBJ | FailReturn<zod.typeToFlattenedError<GetValidatorType<VALIDATOR>>> | FailOfRest<REST>>, GetValidatorType<VALIDATOR>, false>;
// (undocumented)
<O>(actionQrl: (form: JSONObject, event: RequestEventAction, options: ActionOptions) => ValueOrPromise<O>, options?: ActionOptions): Action<StrictUnion<O>>;
<OBJ extends Record<string, any> | void | null, VALIDATOR extends TypedDataValidator>(actionQrl: (data: GetValidatorType<VALIDATOR>, event: RequestEventAction) => ValueOrPromise<OBJ>, options: {
readonly id?: string;
readonly validation: [VALIDATOR];
}): Action<StrictUnion<OBJ | FailReturn<zod.typeToFlattenedError<GetValidatorType<VALIDATOR>>>>, GetValidatorType<VALIDATOR>, false>;
// (undocumented)
<O extends Record<string, any> | void | null, REST extends DataValidator[]>(actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>, ...rest: REST): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;
}

// @public (undocumented)
export interface ActionOptions {
<OBJ extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (data: JSONObject, event: RequestEventAction) => ValueOrPromise<OBJ>, options: {
readonly id?: string;
readonly validation: REST;
}): Action<StrictUnion<OBJ | FailReturn<FailOfRest<REST>>>>;
// (undocumented)
readonly id?: string;
<OBJ extends Record<string, any> | void | null, VALIDATOR extends TypedDataValidator, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (data: GetValidatorType<VALIDATOR>, event: RequestEventAction) => ValueOrPromise<OBJ>, options: VALIDATOR, ...rest: REST): Action<StrictUnion<OBJ | FailReturn<zod.typeToFlattenedError<GetValidatorType<VALIDATOR>>> | FailOfRest<REST>>, GetValidatorType<VALIDATOR>, false>;
// (undocumented)
readonly validation?: DataValidator[];
}

// @public (undocumented)
export interface ActionOptionsWithValidation<B extends TypedDataValidator = TypedDataValidator> {
<OBJ extends Record<string, any> | void | null, VALIDATOR extends TypedDataValidator>(actionQrl: (data: GetValidatorType<VALIDATOR>, event: RequestEventAction) => ValueOrPromise<OBJ>, options: VALIDATOR): Action<StrictUnion<OBJ | FailReturn<zod.typeToFlattenedError<GetValidatorType<VALIDATOR>>>>, GetValidatorType<VALIDATOR>, false>;
// (undocumented)
readonly id?: string;
<OBJ extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<OBJ>, ...rest: REST): Action<StrictUnion<OBJ | FailReturn<FailOfRest<REST>>>>;
// (undocumented)
readonly validation: [val: B, ...a: DataValidator[]];
<OBJ>(actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<OBJ>, options?: {
readonly id?: string;
}): Action<StrictUnion<OBJ>>;
}

// @public (undocumented)
Expand Down Expand Up @@ -273,7 +273,7 @@ export interface Loader<RETURN> {
}

// @public (undocumented)
export type LoaderSignal<T> = T extends () => ValueOrPromise<infer B> ? ReadonlySignal<ValueOrPromise<B>> : ReadonlySignal<T>;
export type LoaderSignal<TYPE> = TYPE extends () => ValueOrPromise<infer VALIDATOR> ? ReadonlySignal<ValueOrPromise<VALIDATOR>> : ReadonlySignal<TYPE>;

// Warning: (ae-forgotten-export) The symbol "MenuModuleLoader" needs to be exported by the entry point index.d.ts
//
Expand Down
2 changes: 0 additions & 2 deletions packages/qwik-city/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export type {
ActionStore,
LoaderSignal,
ActionConstructor,
ActionOptions,
ActionOptionsWithValidation,
FailReturn,
ZodConstructor,
StaticGenerate,
Expand Down
Loading

0 comments on commit 2b856e3

Please sign in to comment.