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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

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.
  • the isMyType(value) utilities no longer type cast the value being checked. They only type the presence of the $type property. Use isValidMyType to assert the type through validation.

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 from cfa432c to 78c8561 Compare January 27, 2025 00:07
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