Skip to content

Conversation

@alistairjcbrown
Copy link
Contributor

Current type declaration for serializer causes errors when used with
enzyme-to-json. Changes:

  • diffOptions is now an optional parameter (as it is in code).
  • Type declaration for the second serialize parameter of the print
    function has been weakened to any due to incorrect type used in
    enzyme-to-json (should be function, but has been typed serializer)
  • Return type declaration from print function has been weakened to
    any; this function is not limited to only returning strings.

Conflicting enzyme-to-json declaration:
https://github.com/adriantoine/enzyme-to-json/blob/d1f86ee82ce014bb3d63f521a5d553307948eff0/index.d.ts#L22-L25

Mismatch of enzyme-to-json serializer type in print function:
https://github.com/adriantoine/enzyme-to-json/blob/d1f86ee82ce014bb3d63f521a5d553307948eff0/src/createSerializer.js#L9-L11

Fixes #108

/cc: @simonsmith @thymikee

Current type declaration for serializer causes errors when used with `enzyme-to-json`. Changes: * `diffOptions` is now an optional parameter (as it is in code). * Type declaration for the second `serialize` parameter of the `print` function has been weakened to `any` due to incorrect type used in `enzyme-to-json` (should be function, but has been typed serializer) * Return type declaration from `print` function has been weakened to `any`; this function is not limited to only returning strings. Conflicting `enzyme-to-json` declaration: https://github.com/adriantoine/enzyme-to-json/blob/d1f86ee82ce014bb3d63f521a5d553307948eff0/index.d.ts#L22-L25 Mismatch of `enzyme-to-json` `serializer` type in `print` function: https://github.com/adriantoine/enzyme-to-json/blob/d1f86ee82ce014bb3d63f521a5d553307948eff0/src/createSerializer.js#L9-L11 Fixes jest-community#108
test: (value: any) => boolean;
print: (value: any, _serializer?: Function) => string;
diffOptions: (valueA: any, valueB: any) => DiffOptions;
print: (value: any, _serializer?: any) => any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave the string return here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee Unfortunately not; the enzyme-to-json type declaration for JestSerializer has print returning their Json type which is an object.

https://github.com/adriantoine/enzyme-to-json/blob/d1f86ee82ce014bb3d63f521a5d553307948eff0/index.d.ts#L24

Keeping it as string give this error:

Type 'JestSerializer' is not assignable to type 'Serializer'. Types of property 'print' are incompatible. Type '(CommonWrapper: any, serializer: JestSerializer) => Json' is not assignable to type '(value: any, _serializer?: any) => string'. Type 'Json' is not assignable to type 'string'. 
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wasn't aware. That's fine then

@thymikee thymikee merged commit 4f6b1ed into jest-community:master Jan 11, 2020
@alistairjcbrown alistairjcbrown deleted the bugfix/correct-serializer-types branch January 11, 2020 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants