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

Improve codegen typings #2999

Merged
merged 20 commits into from
Feb 13, 2025
Merged

Improve codegen typings #2999

merged 20 commits into from
Feb 13, 2025

Conversation

matthieusieben
Copy link
Contributor

@matthieusieben matthieusieben commented Nov 14, 2024

This PR is the first of a 2 steps changes aimed at improving typing in the atproto repo:

Breaking changes

This PR changes the interfaces of the generated code in the following ways:

  • it removes the [x: string]: unknown index signature in objects & records. Because of this, access to un-speccified fields must be explicit.
  • it makes the $type property explicit (though optional, except in open unions). This allows to properly discriminate entity types, especially when used in open unions.
  • it makes the $type property mandatory in record types.
  • the isMyType(value) utilities no longer type cast the value being checked. They only type the presence of the $type property.
  • validating that an unknown value actually matches a lexicon schema can be achieved using the validateMyType(value) utilities.
  • the validateMyType utilities now require that the $type, if present, is valid.
  • The new "asPredicate" helper function allows to convert a validateMyType utility into a type predicate like so: const isValidMyType = asPredicate(validateMyType)

Note

When reviewing, "codegen" commits can be ignored as they only contain generated code changes.

Fixes #2952

@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 3 times, most recently from 2abd90e to ef8af3f Compare November 14, 2024 15:26
@matthieusieben matthieusieben changed the title Improve codegen bundle size Improve codegen bundle size and typings Nov 14, 2024
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 2 times, most recently from bebca0e to 0bea135 Compare November 14, 2024 16:05
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 0bea135 to 02ddb9a Compare November 15, 2024 07:57
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 02ddb9a to 1a337a2 Compare November 15, 2024 10:52
Makefile Outdated Show resolved Hide resolved
packages/syntax/src/tid.ts Outdated Show resolved Hide resolved
packages/lexicon/src/types.ts Show resolved Hide resolved
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 2714235 to 617d86c Compare December 2, 2024 10:32
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 6e398be to 17b3081 Compare December 18, 2024 09:39
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 3 times, most recently from 49690ba to 819eeac Compare January 8, 2025 08:57
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 5e0b6ff to a101316 Compare January 9, 2025 14:33
@matthieusieben matthieusieben changed the title Improve codegen bundle size and typings Improve codegen typings Jan 10, 2025
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 7 times, most recently from 0133f4a to 7fa74c3 Compare January 13, 2025 15:54
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 2 times, most recently from cfa432c to 78c8561 Compare January 27, 2025 00:07
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 3 times, most recently from 9c7ee84 to 8e04164 Compare February 6, 2025 15:11
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 6067ace to 4715c89 Compare February 12, 2025 14:01
@matthieusieben matthieusieben merged commit c53d943 into main Feb 13, 2025
1 check passed
@matthieusieben matthieusieben deleted the msi/lex-gen-optimization branch February 13, 2025 14:21
@github-actions github-actions bot mentioned this pull request Feb 13, 2025
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.

Generation of Omit in lex-cli types causes loss of type safety
3 participants