Skip to content

TypeScript Guidelines - Types: Inference, Annotations, Assertions, Escape Hatches #74

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

Merged
merged 93 commits into from
Apr 30, 2024

Conversation

MajorLift
Copy link
Contributor

@MajorLift MajorLift commented Feb 7, 2024

Motivation

In order to improve type safety and maintainability, we need to establish clear guidelines regarding how to apply types: specifically, when and when not to use explicit type declarations or keywords such as as, any.

Explanation

  • See markdown preview: TypeScript Guidelines - "Types" section
  • The merge conflicts with main will be resolved after the review process to avoid noisy diffs.
  • All examples are tagged with a permalink for easy reference and quotation.

Table of Contents

  • Types
    • Type Inference
    • Type Annotations (:, satisfies)
    • Type Assertions (as, !)
    • Escape Hatches (any, @ts-expect-error)

Details

  • Dangers and advantages.
  • Tips for avoiding.
  • Acceptable use cases.

References

@MajorLift MajorLift self-assigned this Feb 7, 2024
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch from f8d8310 to ecf59b1 Compare February 8, 2024 08:55
@MajorLift MajorLift changed the title TypeScript guidelines - Overriding types (infer, :, as, any) TypeScript Guidelines - Types: Inference, Annotations, Assertions, Directives Feb 21, 2024
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch 3 times, most recently from 8c2fbe0 to b4511bc Compare February 29, 2024 15:55
@MajorLift MajorLift marked this pull request as ready for review February 29, 2024 15:56
@MajorLift MajorLift requested a review from a team as a code owner February 29, 2024 15:56
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch from d5c1704 to c5a59b8 Compare February 29, 2024 16:01
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch from c5a59b8 to b9644ca Compare February 29, 2024 21:12
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch from adbe5ca to 513a52a Compare March 1, 2024 06:05
@MajorLift MajorLift requested a review from DDDDDanica March 1, 2024 06:33
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch from 4c8fb5c to 44d575c Compare March 3, 2024 20:05
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch from 44d575c to 39795dc Compare March 3, 2024 20:07
@MajorLift MajorLift force-pushed the 240206-typescript-guidelines-any-as branch from 69a0989 to b1385fc Compare March 21, 2024 16:49
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Lots of good stuff to chew on here! I skimmed through it one more time. This gets me thinking that it may be valuable to have two different kinds of documents in the future, one that's purely "do"s and "don't"s, and another that is a bit more expositional. We can decide on that in the future though. Nice work!

@MajorLift MajorLift changed the title TypeScript Guidelines - Types: Inference, Annotations, Assertions, Directives TypeScript Guidelines - Types: Inference, Annotations, Assertions, Escape Hatches Apr 30, 2024
@MajorLift MajorLift merged commit d504b33 into main Apr 30, 2024
6 checks passed
@MajorLift MajorLift deleted the 240206-typescript-guidelines-any-as branch April 30, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TS guideline: "Document safe or necessary uses of type assertions" Add entry forany, as usage in TypeScript Guidelines doc
4 participants