-
Notifications
You must be signed in to change notification settings - Fork 572
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
Add explicit $type property in code gen #2956
base: main
Are you sure you want to change the base?
Conversation
f22ff9f
to
005584a
Compare
f5707e0
to
3e52922
Compare
4677431
to
35acae1
Compare
35acae1
to
2cc15f3
Compare
2cc15f3
to
c71eccc
Compare
c71eccc
to
1f8f816
Compare
ef8af3f
to
bebca0e
Compare
1f8f816
to
3784372
Compare
bebca0e
to
0bea135
Compare
66b3c0c
to
6ae8660
Compare
fe5bb04
to
9117a3e
Compare
6bd421c
to
f6f0ead
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one was overwhelming to review, even if the non-codegen commit. I "reviewed" it.
a484578
to
e3c766c
Compare
return this.recordEmbedWrapper( | ||
{ ...view, $type: 'app.bsky.feed.defs#generatorView' }, | ||
withTypeTag, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good example of the benefit of this change. Before, because $type
was optional, the type system did not force the $type
property to be present in unions.
Now, because it is no longer optional in unions, not specifying the $type
here results in a type error.
@@ -2,7 +2,7 @@ | |||
"$schema": "https://json.schemastore.org/tsconfig", | |||
"extends": "./base.json", | |||
"compilerOptions": { | |||
"lib": ["ES2022", "DOM", "DOM.Iterable", "ESNext.Disposable"], | |||
"lib": ["ES2023", "DOM", "DOM.Iterable", "ESNext.Disposable"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeJS 18 (our minimal version) uses ES2023.
The api
package already relies on ES2023 features (Array.findLast
).
fa6f004
to
344ac6b
Compare
344ac6b
to
f912407
Compare
2bbbdeb
to
7ddbc91
Compare
6e398be
to
17b3081
Compare
7ddbc91
to
235b34d
Compare
} | ||
} else { | ||
return { | ||
$type: 'com.atproto.admin.defs#repoViewNotFound', | ||
$type: 'tools.ozone.moderation.defs#repoViewNotFound', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
com.atproto.admin.defs#repoViewNotFound
does not exist.
This is a bug that was outlined by the type system thanks to the changes from this PR.
235b34d
to
ba0dfe5
Compare
Part of #2999
Fixes #2952
Breaking changes
This PR changes the interfaces of the generated code in the following ways:
[x: string]: unknonw
index signature in objects & records. Because of this, access to un-speccified fields must be explicit.$type
property explicit (though optional, except in open unions). This allows to properly discriminate entity types, especially when used in open unions.isMyType(value)
utilities no longer type cast thevalue
being checked. They only type the presence of the$type
property. UseisValidMyType
to assert the type through validation.Note
Using
main
instead ofmsi/lex-gen-optimization
(#2999) as "base branch" to allows CI to run.Note
While reviewing, "codegen" commits can be ignored ;-)