Closed ChrisCrewdson closed 4 years ago
Thanks @ChrisCrewdson we can fix your error with this: https://github.com/ChrisCrewdson/joi-extract-type/pull/1
Did you try not to move outside Joi namespace? To prevent this breaking change?
Hey guys, after some tests, I couldn't find a way to make the extraction without working on the same Joi namespace.
This is because we need to augment Joi methods to generate the types in the first place.
When we do Joi.object()
it needs to generate the generic in the background. Working on another namespace (like JoiExtract) prevents this.
Nowadays, Joi types export a Joi.Root
interface containing those methods, but for some reason they don't merge the same way as before.
Here is an example. When I do something like:
import '@hapi/joi';
declare namespace Joi {
export type sometype = boolean
}
I cant find Joi.sometype
as I could before.
And when I do:
import '@hapi/joi';
declare module '@hapi/joi' {
namespace Joi { // with or without the namespace
type test = StringSchema
}
}
I get Exported type alias 'test' has or is using private name 'StringSchema'.ts(4081)
Which means I can't access StringSchema. Even after I exported the schemas within @types/hapi__joi
.
Anyone has any idea why this is happening? Or how to deal with it?
I pushed a branch trying to merge the Root
interface:
https://github.com/TCMiranda/joi-extract-type/blob/feature/chris-joi16-namespace-fix/index.ts#L443
@guyellis just pinging you here to focus the conversation on this approach
Any update on this PR?
No updates. I don't this that this approach will solve the issue @azai91
Just wondering: Wouldn't it be a solution to move extractType outside the Joi namespace? I think support for Joi version 16+ would be more important than backwards compatibility for this breaking change.
Unfortunately, we need another approach for @16, I'll close this for now to focus on the issue #22 Thanks
We are attempting to solve Issue 22 and I think we're close. There are a few changes including:
__stringSchema
to keep them distinctThis is the remaining error:
This is isolated because commenting the
when
section has no other tsc issues. Can someone help with this typescript error?