Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use TS assertion signature to avoid type casting #30

Merged
merged 1 commit into from
Jan 9, 2022
Merged

Use TS assertion signature to avoid type casting #30

merged 1 commit into from
Jan 9, 2022

Conversation

kubk
Copy link
Contributor

@kubk kubk commented Jan 9, 2022

Starting from TS 3.7 it's possible to use so-called "assertion signatures" to narrow TS types after guard statements. It's described here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions

It allows to avoid type casting. For some reason assertion signatures are available only for function keyword, that's why I had replace const with function

  • This PR only introduces changes to documentation.
    • No
  • This PR adds new functionality
    • Is there a related issue?
      • No, it's just a an improvement utilizing latest TS features
    • Does the code style reasonably match the existing code?
      • Yes
    • Are the changes tested (using the existing format, as far as is possible?)
      • Yes
    • Are the changes documented in the readme with a suitable example?
      • Not needed
    • Is the table of contents updated?
      • Not needed
    • Is the index.d.ts file updated, using the same (or appropriately modified) description as in the readme?
      • Not needed

@francisrstokes francisrstokes merged commit 2ca1851 into francisrstokes:main Jan 9, 2022
@francisrstokes
Copy link
Owner

Definitely an improvement, thanks @kubk! 🎉

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants