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

Generation of Omit in lex-cli types causes loss of type safety #2952

Open
tom-sherman opened this issue Nov 6, 2024 · 4 comments · May be fixed by #2956
Open

Generation of Omit in lex-cli types causes loss of type safety #2952

tom-sherman opened this issue Nov 6, 2024 · 4 comments · May be fixed by #2956
Labels
bug Something isn't working

Comments

@tom-sherman
Copy link

Describe the bug

Methods like create that accept an InputSchema lose their type safety and accept any object value.

To Reproduce

Steps to reproduce the behavior:

client.app.bsky.feed.post.create(
    // @ts-expect-error Should be missing repo here
    {},
    post
)

client.app.bsky.feed.post.delete(
    // @ts-expect-error Should be missing rkey and repo here
    {}
)

Expected behavior

Type errors should happen above. See playground.

Details

This is caused by the use of Omit on a type with an index signature. This is expected behaviour of typescript see microsoft/TypeScript#45367

Additional context

@tom-sherman
Copy link
Author

I think changing the Omit to be an intersection with the property set to unknown could work here eg.

- Omit<InputSchema, "collection">
+ InputSchema & { collection?: unknown }

@matthieusieben matthieusieben linked a pull request Nov 7, 2024 that will close this issue
@tom-sherman
Copy link
Author

Hmm, the suggestion above doesn't work actually. Not sure what the workaround is then.

@matthieusieben
Copy link
Contributor

Basically have no other choice than removing the [x: string]: unknown index signature from the InputSchema interface.

Doing so causes a bunch of breaking changes though :/ (see related PR)

@tom-sherman
Copy link
Author

@matthieusieben looks like there's a solution in #2968 🙌

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
None yet
2 participants