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

Upgrade to TS 2.8 #342

Merged
merged 11 commits into from
Apr 17, 2018
Merged

Upgrade to TS 2.8 #342

merged 11 commits into from
Apr 17, 2018

Conversation

forabi
Copy link
Contributor

@forabi forabi commented Mar 5, 2018

TypeScript 2.8 has a pretty cool feature, called Conditional Types, that allows us to do type-level programming, including things like:

  • Excluding keys from object types with the new built-in Exclude<T, U>
  • Unboxing types wrapped in promises like this: type UnboxPromise<T> = T extends Promise<infer R> ? R : T
  • Getting the return type of a function with the new built-in ReturnType<T>.
  • Removing null and undefined from types, with the new built-in NonNullable<T>.

NonNullable is particularly useful for us because we can get rid of non-null assertions in components that consume API queries that could possibly have a null value. See the diff to get an idea of how this could simplify our types.

Not merging this for now because:

  • TypeScript 2.8 is not stable yet, will be released this month.
  • typescript-eslint-parser is failing on the new infer R and T extends R ? ... syntax.

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@ea4dd75). Click here to learn what that means.
The diff coverage is 80.76%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #342   +/-   ##
=========================================
  Coverage          ?   80.19%           
=========================================
  Files             ?       90           
  Lines             ?      919           
  Branches          ?      113           
=========================================
  Hits              ?      737           
  Misses            ?      126           
  Partials          ?       56
Impacted Files Coverage Δ
.../app/pages/NotablePerson/NotablePerson.module.scss 100% <ø> (ø)
.../app/pages/NotablePerson/LoadableNotablePerson.tsx 100% <100%> (ø)
...components/PersonDetails/PersonDetails.module.scss 100% <100%> (ø)
...p/components/EditorialSummary/EditorialSummary.tsx 79.41% <100%> (ø)
.../pages/NotablePerson/NotablePersonBodyDummyData.ts 50% <50%> (ø)
src/app/components/PersonDetails/PersonDetails.tsx 71.42% <72.72%> (ø)
src/app/pages/NotablePerson/NotablePersonBody.tsx 80% <80%> (ø)
src/app/pages/NotablePerson/NotablePerson.tsx 84.37% <86.2%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea4dd75...3bc776a. Read the comment docs.

@forabi
Copy link
Contributor Author

forabi commented Mar 5, 2018

Hmm, I thought I disabled codecov comments 🤔

Anyway, here are the built-in conditional types that will be available in TS 2.8: microsoft/TypeScript#21847

@wholesomedev
Copy link
Contributor

Dude, this is awesome and just in time. Yesterday I was googling for "typescript how to remove null from type" and now I have my answer!

@forabi
Copy link
Contributor Author

forabi commented Mar 6, 2018

Yep! Conditional types are very powerful!

@forabi forabi merged commit fbb1059 into hollowverse-archive:master Apr 17, 2018
Copy link
Contributor

@wholesomedev wholesomedev left a comment

Choose a reason for hiding this comment

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

🎉

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.

3 participants