bluesky-social / atproto

Social networking technology created by Bluesky
Other
6.89k stars 486 forks source link

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

Open tom-sherman opened 2 weeks ago

tom-sherman commented 2 weeks ago

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 https://github.com/microsoft/TypeScript/issues/45367

Additional context

tom-sherman commented 2 weeks ago

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 }
tom-sherman commented 2 weeks ago

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

matthieusieben commented 1 week ago

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 commented 1 week ago

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