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

Fix StatusListener typing #98

Merged
merged 3 commits into from
Nov 17, 2022
Merged

Conversation

mifopen
Copy link
Contributor

@mifopen mifopen commented Nov 17, 2022

Fixed details type for syncError type and made it more inferring-friendly

@ai
Copy link
Member

ai commented Nov 17, 2022

Will it remove the argument names from the autocomplete?

Can we define a multiple interfaces instead?

Like:

interface StatusListener {
  ('synchronized'): void
  ('syncError', { error: Error })
  
}

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

Will it remove the argument names from the autocomplete?

No.

Can we define a multiple interfaces instead?

It doesn't work with inferring. So you won't be able to write

status(store.client, (state, details) => {
  switch(status) {
    case 'syncError':
      console.log(details.error); // <- here details is inferred as { error: Error }
    // ... <- here you can use your IDE to generate all the branches as state is correct union type
});

@ai
Copy link
Member

ai commented Nov 17, 2022

It doesn't work with inferring

Got it.

Can you fix a type test and we can release it.

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

On it

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

The only downside (I guess because of the amateur TS support of the feature) is that you can not pass a callback with one parameter in the signature — it must be the full tuple. Had do ignore eslint warning about unused argument in test

@ai
Copy link
Member

ai commented Nov 17, 2022

The only downside (I guess because of the amateur TS support of the feature) is that you can not pass a callback with one parameter in the signature

Not a solution

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

The only downside (I guess because of the amateur TS support of the feature) is that you can not pass a callback with one parameter in the signature

Not a solution

Could you please elaborate on what you mean by that? :)

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

I guess it's backwards incompatible. Ok, I see

@ai
Copy link
Member

ai commented Nov 17, 2022

I guess it's backwards incompatible. Ok, I see

Yes. But also it is not useful.

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

I guess it's backwards incompatible. Ok, I see

Yes. But also it is not useful.

Besides backward incompatibility, I don't see any downsides. It's definitely better than it was because you don't have to check the structure of the details before accessing it.

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

Will try to fix it somehow

@ai
Copy link
Member

ai commented Nov 17, 2022

Besides backward incompatibility, I don't see any downsides.

You need to disable linter if you need only single argument

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

Yeah, I know. That's what I'm trying to deal with

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

Ok, the current approach is the recommended one by TS https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/#control-flow-analysis-for-dependent-parameters
And there is no workaround for not declaring the second parameter in this case. And of course, the language does nothing with the fact that someone wants to use such lint rules. So for a better solution here we have to wait for microsoft/TypeScript#22609.
I will close the PR and patch the package locally for us as we always use details parameter. Sorry for bothering you.

@mifopen
Copy link
Contributor Author

mifopen commented Nov 17, 2022

aeh, there is a bug so let's fix it at least :)

@ai ai merged commit 1cb7958 into logux:main Nov 17, 2022
@ai
Copy link
Member

ai commented Nov 17, 2022

Thanks. Released in 0.18.4.

@mifopen mifopen deleted the fix-state-listener-typings branch November 17, 2022 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants