Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve @ts-expect-error directives #776

Closed
alecmev opened this issue Aug 12, 2024 · 7 comments
Closed

Preserve @ts-expect-error directives #776

alecmev opened this issue Aug 12, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request priority This has priority

Comments

@alecmev
Copy link

alecmev commented Aug 12, 2024

As mentioned in #659 (comment), some prefer to keep skipLibCheck off. It's not about being pedantic, it can help explain otherwise cryptic errors (speaking from experience), and puts pressure on the ecosystem to keep their types clean.

However, in this case it isn't an easy fix at all (looks like QuestionMarkSchema being recursive pushes the limits of inference, microsoft/TypeScript#30134, microsoft/TypeScript#47599). Hit my head for half an hour, to no avail.

Thankfully, this repo already has // @ts-expect-error peppered throughout:

export type QuestionMarkSchema =
| NullishSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown>
| OptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown>
// @ts-expect-error
| LazySchema<QuestionMarkSchema>
| NonNullableSchema<
// @ts-expect-error
QuestionMarkSchema,
ErrorMessage<NonNullableIssue> | undefined
>;

So all that needs to be done is just preserve these in the emitted .d.ts. Easier said than done, as I haven't been able to find if tsc can even do it, but worst case, at least it could be a post-build script just adding these back in above QuestionMarkSchema and QuestionMarkSchemaAsync, and inside of TuplePath.

@fabian-hiller
Copy link
Owner

A better solution would be to figure out how to avoid the recursive inference problem. If we can't find a solution, we could try to limit the recursiveness to a certain depth. Are you interested in exploring this problem?

@fabian-hiller fabian-hiller self-assigned this Aug 13, 2024
@fabian-hiller fabian-hiller added enhancement New feature or request priority This has priority labels Aug 13, 2024
@alecmev
Copy link
Author

alecmev commented Aug 13, 2024

Done 😉 #778

@fabian-hiller
Copy link
Owner

Related issue at the TS repo: microsoft/TypeScript#38628

@alecmev
Copy link
Author

alecmev commented Aug 18, 2024

Good find! Looking at that issue, how about /** @ts-expect-error */? TypeScript preserves doc comments.

@fabian-hiller
Copy link
Owner

This may work, but it is a dirty hack. I would prefer an official solution, or that we rethink our implementation. But I will consider it.

@fabian-hiller
Copy link
Owner

This will probably be fixed in the next version.

@fabian-hiller
Copy link
Owner

v0.38.0 is available 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority This has priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants