Closed csantos-nydig closed 1 year ago
correct, mixed
is not the base schema in v1, please add your method to Schema
according to the docs
@jquense thanks for the quick answer
addMethod(Schema, "forAll", function forAll() {
return this.transform(() => {
return "just for testing";
});
});
It works in Javascript but it fails TypeScript, see the updated codesandox: https://codesandbox.io/s/mixed-yup1-0-2-forked-l56m8r
You also need to extend the type correctly, including the generics
You also need to extend the type correctly, including the generics
Where can I find this in the documentation? Sorry to keep bothering you.
I see https://github.com/jquense/yup#extending-built-in-schema-with-new-methods which only covers string
not Schema
. plus this is for when I want to use my added method, not for calling addMethod
per-se.
I'm not sure you looked at the codesandbox.io/s/mixed-yup1-0-2-forked-l56m8r, but let me add an image here to show you where the TypeScript errors shows up:
I also cloned yup
repository locally, and pasted in my code in one of the ts files: the typescript error is the same
I see you have unit tests for addMethod
https://github.com/jquense/yup/blob/master/test/yup.js#L206-L211, but that file is written in JavaScript, so the TypeScript error doesn't show up
but the TS error appears if you move this simple line from .js
to .ts
:
addMethod(Schema, 'foo', () => 'here');
I don't think it has anything to do with the declare
statement, which is actually working: see the green box in the screenshot above, and it also works fine when executed.
So the TS error is when calling addMethod
on Schema
not when using the added method. 👇
before
v1.x
I was able to add a method tomixed
and this method would be available to all helpers (i.e.string
,number
,date
, etc)To Reproduce
string().forAll()
: forAll is not a functionExpected behavior
forAll
method should be in string because it was added tomixed
as it used to work on yupv0.32.11
Platform (please complete the following information):
v1.x