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

use error keys insted of values for typescript #1115

Merged
merged 1 commit into from
Sep 10, 2020
Merged

use error keys insted of values for typescript #1115

merged 1 commit into from
Sep 10, 2020

Conversation

rtm7777
Copy link
Contributor

@rtm7777 rtm7777 commented Sep 8, 2020

Hello,

I tried to check dexie error name in my typescript project next way:

  } catch (err) {
    switch (err.name) {
      case Dexie.errnames.Constraint:
        console.log('already exist')
        break
      default:
        console.log('other error')
    }
  }

And I have the next error:

Property 'Constraint' does not exist on type '{ OpenFailedError: "OpenFailedError"; VersionChangeError: "VersionChangeError"; SchemaError: "SchemaError"; UpgradeError: "UpgradeError"; InvalidTableError: "InvalidTableError"; ... 24 more ...; BulkError: "BulkError"; }'.

I think it's because you use values of error names as keys

But I'm new to TS so I may be wrong

Thanks!

Copy link
Collaborator

@dfahlander dfahlander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this typing issue! Do you agree on my comments? If so, could you commit the 2 changes and push it back?

src/errors/errors.d.ts Outdated Show resolved Hide resolved
src/public/types/dexie-constructor.d.ts Outdated Show resolved Hide resolved
@rtm7777
Copy link
Contributor Author

rtm7777 commented Sep 10, 2020

@dfahlander thanks for taking a look at my PR, changes pushed

@dfahlander dfahlander merged commit bf3a6fc into dexie:master Sep 10, 2020
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.

None yet

2 participants