Skip to content

Commit

Permalink
Minor fixes (#126)
Browse files Browse the repository at this point in the history
Improve typings for custom type

* flip custom() declarations order so inferrence works properly

* type context properly

* re-gen docs
  • Loading branch information
NaridaL committed Mar 29, 2020
1 parent c0fc742 commit 118193c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ const json = serialize(todoSchema, { title: 'Test', done: false })
const todo = deserialize(todoSchema, json)
```

### _function_ `custom`(_serializer_: [PropSerializer](#type-propserializer--sourcepropertyvalue-any-key-string--number--symbol-sourceobject-any--any--typeof-skip-src), _deserializer_: (_jsonValue_: any, _context_: any, _oldValue_: any) => any | typeof [SKIP](typedoc-id-undefined), _additionalArgs_?: [AdditionalPropArgs](#type-additionalpropargs--pickpropschema-beforedeserialize--afterdeserialize--pattern-src)): [PropSchema](#interface-propschemasrc) <sub><a href="src/types/custom.ts#L63">src</a></sub>
### _function_ `custom`(_serializer_: [PropSerializer](#type-propserializer--sourcepropertyvalue-any-key-string--number--symbol-sourceobject-any--any--typeof-skip-src), _deserializer_: (_jsonValue_: any, _context_: [Context](typedoc-id-undefined), _oldValue_: any, _callback_: (_err_: any, _result_: any | typeof [SKIP](typedoc-id-undefined)) => void) => void, _additionalArgs_?: [AdditionalPropArgs](#type-additionalpropargs--pickpropschema-beforedeserialize--afterdeserialize--pattern-src)): [PropSchema](#interface-propschemasrc) <sub><a href="src/types/custom.ts#L64">src</a></sub>

Can be used to create simple custom propSchema. Multiple things can be done inside of a custom propSchema, like deserializing and serializing other (polymorphic) objects, skipping the serialization of something or checking the context of the obj being (de)serialized.

Expand Down Expand Up @@ -548,7 +548,7 @@ deserialize(schemaWithAsyncProps, { "a": 6 }, (err, res) => {
}
```
### _function_ `custom`(_serializer_: [PropSerializer](#type-propserializer--sourcepropertyvalue-any-key-string--number--symbol-sourceobject-any--any--typeof-skip-src), _deserializer_: (_jsonValue_: any, _context_: any, _oldValue_: any, _callback_: (_err_: any, _result_: any | typeof [SKIP](typedoc-id-undefined)) => void) => void, _additionalArgs_?: [AdditionalPropArgs](#type-additionalpropargs--pickpropschema-beforedeserialize--afterdeserialize--pattern-src)): [PropSchema](#interface-propschemasrc) <sub><a href="src/types/custom.ts#L68">src</a></sub>
### _function_ `custom`(_serializer_: [PropSerializer](#type-propserializer--sourcepropertyvalue-any-key-string--number--symbol-sourceobject-any--any--typeof-skip-src), _deserializer_: (_jsonValue_: any, _context_: [Context](typedoc-id-undefined), _oldValue_: any) => any | typeof [SKIP](typedoc-id-undefined), _additionalArgs_?: [AdditionalPropArgs](#type-additionalpropargs--pickpropschema-beforedeserialize--afterdeserialize--pattern-src)): [PropSchema](#interface-propschemasrc) <sub><a href="src/types/custom.ts#L74">src</a></sub>
### _function_ `date`(_additionalArgs_?: [AdditionalPropArgs](#type-additionalpropargs--pickpropschema-beforedeserialize--afterdeserialize--pattern-src)): [PropSchema](#interface-propschemasrc) <sub><a href="src/types/date.ts#L9">src</a></sub>
Expand Down
17 changes: 9 additions & 8 deletions src/types/custom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { invariant, processAdditionalPropArgs } from "../utils/utils"
import { AdditionalPropArgs, PropSchema, PropSerializer } from "../api/types"
import { SKIP } from "../constants"
import Context from "../core/Context"

/**
* Can be used to create simple custom propSchema. Multiple things can be done inside of a custom
Expand Down Expand Up @@ -60,28 +61,28 @@ import { SKIP } from "../constants"
*/
// Two function declarations, otherwise TypeScript has trouble inferring the argument types of the
// deserializer function.
export default function custom(
serializer: PropSerializer,
deserializer: (jsonValue: any, context: any, oldValue: any) => any | typeof SKIP,
additionalArgs?: AdditionalPropArgs
): PropSchema
export default function custom(
serializer: PropSerializer,
deserializer: (
jsonValue: any,
context: any,
context: Context,
oldValue: any,
callback: (err: any, result: any | typeof SKIP) => void
) => void,
additionalArgs?: AdditionalPropArgs
): PropSchema
export default function custom(
serializer: PropSerializer,
deserializer: (jsonValue: any, context: Context, oldValue: any) => any | typeof SKIP,
additionalArgs?: AdditionalPropArgs
): PropSchema
export default function custom(
serializer: PropSerializer,
deserializer:
| ((jsonValue: any, context: any, oldValue: any) => any | typeof SKIP)
| ((jsonValue: any, context: Context, oldValue: any) => any | typeof SKIP)
| ((
jsonValue: any,
context: any,
context: Context,
oldValue: any,
callback: (err: any, result: any | typeof SKIP) => void
) => void),
Expand Down

0 comments on commit 118193c

Please sign in to comment.