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

Tuple checks fail to compile with noUncheckedIndexedAccess #804

Closed
stevarino opened this issue Sep 4, 2023 · 2 comments
Closed

Tuple checks fail to compile with noUncheckedIndexedAccess #804

stevarino opened this issue Sep 4, 2023 · 2 comments
Assignees
Labels
bug Something isn't working
Projects

Comments

@stevarino
Copy link

📝 Summary

Write a short summary of the bug in here.

  • Typia Version: 4.1.11, 5.0.1-dev.20230831
  • Expected behavior: Tuple checks compile with noUncheckedIndexedAccess enabled
  • Actual behavior: Receives syntax error on tsc evaluation.

Write detailed description in here.

When trying to write a validator that accepts tuples (with noUncheckedIndexedAccess enabled) I receive the following errors:

src/types_gen/dialogueTypes.ts:39:21 - error TS2532: Object is possibly 'undefined'.
 39                 if (pred[0](array))

... more of the same...

I believe the fix is simply to change the compiled code to be if (pred[0]!(array)) as it looks overall a safe lookup. I believe this can be accomplished by adding the exclamation marks to the createIdentifier lines on 136 and 142 (but not familiar enough with the code to be sure): https://github.com/samchon/typia/blob/b0005b7516d58dadcda9f2afbaf645cc42a165e1/src/programmers/internal/check_union_array_like.ts#L136C9-L142C67

⏯ Playground Link

https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDANHA3g1BzAZzgF84AzKCEOAIiRVRoG4AoF4AOxgFMozUAxtzgAxCBGxwpcFlIBGqKAC44AbQ4BXEHN6YAdAc3beqgLqmAPqoIwonPPoM27HPGdMtibAPTeAtAF+LL5wAGoAggAyAJIAIuEAKtEA8gBywf6BLPRoegJQ3Kg80QQAPGIQAHwAFACUrBmBQSEASuGpsckAso1ZOah5BUXcLagcACZU5eI19T6ZARlwAFIAymm9i-16AFYEEByDhTyrtvbAZIjTVXUNIb5NSyEACi3JCckAwsmRcABCAFURCIAKItJ4LZreBDIXJgSgwCByDRkI7DEEcAQQcbca6zVhAA

💻 Code occuring the bug

import typia from "typia";

interface Foo {
  bar: [number, ...number[]]|[string, ...string[]]
}

const test = typia.createValidateEquals<Foo>();
@samchon samchon self-assigned this Sep 4, 2023
@samchon samchon added the bug Something isn't working label Sep 4, 2023
@samchon samchon added this to To do in V5 Update via automation Sep 4, 2023
@samchon samchon closed this as completed in 4b91066 Sep 5, 2023
samchon added a commit that referenced this issue Sep 5, 2023
Fix #804 - support `noUncheckedIndexedAccess` option.
V5 Update automation moved this from To do to Done Sep 5, 2023
@samchon
Copy link
Owner

samchon commented Sep 5, 2023

Thanks for bug reporting. Upgrade to v5.0.2, then it would be fixed.

@stevarino
Copy link
Author

Woah, was not expecting a fix this fast!

Confirmed on my end, and now I can delete ~30 lines of validation code.

Thanks so much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

No branches or pull requests

2 participants