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

Indexed Access Types: Revised #5

Merged
merged 6 commits into from
Apr 16, 2023
Merged

Indexed Access Types: Revised #5

merged 6 commits into from
Apr 16, 2023

Conversation

sinclairzx81
Copy link
Owner

@xddq Hey, just submitting and updated PR for the Indexed Access Types. Wanted to simplify the accessor resolution and avoid the property collection / depth introspection https://github.com/sinclairzx81/typebox-codegen/pull/2/files#diff-2d6cde5bd1603d51af990557190f42976eba2d85f2a87556bc5535d0e18c3b2cR118-R248

Implementation of Indexed Accessor Types is basically just reduced to the following (where we trust the compiler to produce the correct objectType and indexType. The output just yields a T.properties[key]. This function is called from the Visit(node) function.

function* IndexedAccessType(node: ts.IndexedAccessTypeNode): IterableIterator<string> {
  const obj = node.objectType.getText()
  const key = node.indexType.getText()
  yield `${obj}.properties[${key}]`
}

This PR also implements unit tests for the model transformation. To keep dependencies to an absolute minimum (and to avoid babel side dependencies), I'm trialing the new Node test runners https://nodejs.org/api/test.html. These are built into Node nowadays and should be supported on modern versions Node16, 18 and 19 (I'm running 18 LTS this side). These seem to work ok (but the test filtering Node implemented needs work).

I usually use mocha, but depending on how well Node test runners hold up, can swap to Jest as the setup should largely be the same.

@sinclairzx81 sinclairzx81 changed the title Index Access Types: Revised Indexed Access Types: Revised Apr 16, 2023
@sinclairzx81 sinclairzx81 merged commit b717629 into main Apr 16, 2023
@sinclairzx81 sinclairzx81 deleted the indexers branch April 16, 2023 07:54
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.

None yet

1 participant