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

Refactor: type improvements #7972

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Beraliv
Copy link

@Beraliv Beraliv commented May 1, 2024

Summary

  • Added ts-essentials@10 as dev dependency
  • Replaced 4 type utilities: ValueOf, Merge, MarkOptional and MarkRequired
  • Removed NonOptional as it's not used
  • Simplified ForwardRef (which helped remove SignatureType and CallableType) - inferred type is the same for my VSCode
  • Provided reasons why you may benefit from our library

Potential benefits

Hey @dwelle and @ad1992!

I'm the maintainer of ts-essentials right now.

I've seen you're already using ts-essentials types ValueOf, Merge, MarkOptional and MarkRequired so I thought it's worth checking if you'd like to include ts-essentials as a dev dependency.

The benefits that you're getting from the library are:

  1. Extensive unit tests for all the types that we have, e.g.:
  2. We test against many TypeScript versions, e.g. our GHA for CI checks - https://github.com/ts-essentials/ts-essentials/blob/master/.github/workflows/typecheck.yml#L16 (currently, it includes TS version between 4.5 and 5.4, 5.5 will be included soon once it's out of beta)
  3. We can help you cover all types that you need (they are located in packages/excalidraw/utility-types.ts as far as I understand):
    • Mutable can be replaced with Writable
    • NestedKeyOf can be replaced with Paths
    • MaybePromise can be replaced with AsyncOrSync
  4. We can provide future improvements if you'd like to collaborate more:
    • ExtractSetType can be potentially replaced with ElementOf (I can create an issue to extend ElementOf for sets and make it available as a patch release 10.0.1)
    • Assert and SameType (usually called IsExact) can be introduced as a minor release 10.1.0
    • MakeBrand looks similar to Opaque but I need to understand how you use it (Intellisense is mentioned in the comment, I need to confirm it with you)
    • MarkNonNullable can be added, similarly to other mark types, e.g. MarkRequired

I will leave it up to you, hope it's helpful!

Copy link

vercel bot commented May 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
excalidraw ✅ Ready (Inspect) Visit Preview May 1, 2024 11:52pm
excalidraw-package-example ✅ Ready (Inspect) Visit Preview May 1, 2024 11:52pm
excalidraw-package-example-with-nextjs ✅ Ready (Inspect) Visit Preview May 1, 2024 11:52pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview May 1, 2024 11:52pm

@dwelle
Copy link
Member

dwelle commented May 2, 2024

Hi Alexey! Thanks for offering to help! As you have seen, we've taken some types from ts-essentials already. Some were just inspired, or share the same type/name by chance. :)

As for taking on the dependency, I don't see that as a problem necessarily, but a thought to kick off the discussion:

Some types we don't need to be too generic (e.g. our NestedKeyOf vs Paths), and keeping much simpler ones will likely improve codebase perf (though question is how much). We start simple, prototype/iterate on what need, sometimes tweak based on what result it gives in vscode intellisense (or more generally the TS language server).

Will go over the changes and give more detailed notes later!

@Beraliv
Copy link
Author

Beraliv commented May 3, 2024

@dwelle Thank you for taking the time to consider my suggestions!

I'm happy with your approach, if I can support you (it doesn't matter with or without ts-essentials), please let me know!

Performance can be easily measured with --extendedDiagnostics, I can invest some time to measure it in your project. If it's something you're doing and interested in, I'm happy to do it.

VSCode IntelliSense (i.e. inferred type or suggestions) can be also properly tested - I haven't looked at it myself, but I have seen that some projects are especially advanced. Not sure I know all the answers yet, but happy to investigate it and help if you're interested.

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