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

🚀 Feature: Normalize union ordering and readonly array syntax #108

Open
3 tasks done
JoshuaKGoldberg opened this issue Dec 11, 2023 · 3 comments
Open
3 tasks done
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request

Comments

@JoshuaKGoldberg
Copy link
Owner

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

Splitting out from microsoft/DefinitelyTyped-tools#858 (comment): @definitelytyped/expect internally "normalizes" commented types by creating a virtual source file with a type annotation, then stringifying the type annotation. https://github.com/microsoft/DefinitelyTyped-tools/blob/3d6c2ffd0b38eac222e03156c3d62d6020b2b94b/packages/eslint-plugin/src/rules/expect.ts#L492

That feature is particularly useful for when you have multiple TS versions (#107). It's also generally nice to be a little less nitpicky for users (see also: #18). Let's take that feature in here!

Additional Info

No response

@jakebailey
Copy link

I will note that our existing normalization both before and after are imperfect, specifically for readonlyness. It's totally possible for someone to have declared a type named ReadonlyArray and it conflict such that an expect passes, but the risk seemed quite minimal.

Union sorting should be fine, though it does have a perf cost (that is avoided on exact matches).

@danvk
Copy link
Collaborator

danvk commented Jan 6, 2024

@jakebailey
Copy link

jakebailey commented Jan 6, 2024

I would recommend not parsing any type strings without calling TS's parser; this kind of code wouldn't handle string literal types containing | (which is why I did it differently in the rule for DT).

@JoshuaKGoldberg JoshuaKGoldberg changed the title 🚀 Feature: normalize union ordering and readonly array syntax 🚀 Feature: Normalize union ordering and readonly array syntax Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request
Projects
None yet
Development

No branches or pull requests

3 participants