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

Weak type inference in JSX leaf nodes leads to unknown types #99

Open
EvanBoyle opened this issue Jan 13, 2025 · 0 comments
Open

Weak type inference in JSX leaf nodes leads to unknown types #99

EvanBoyle opened this issue Jan 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@EvanBoyle
Copy link
Member

EvanBoyle commented Jan 13, 2025

Due to limitations in the way that typescript handles JSX type checking, there are a few areas where (1) we are unable to infer types and have to be more explicit about type declarations and (2) typing bottoms out on unknown for the last child element in a workflow.

An example of (2):

export const HNAnalyzerWorkflow = gsx.Component<
  HNAnalyzerWorkflowProps,
  HNAnalyzerWorkflowOutput
>(({ postCount }) => (
  <OpenAIProvider apiKey={process.env.OPENAI_API_KEY}>
    {() => (
      <HNCollector limit={postCount}>
        {(stories) => (
          <AnalyzeHNPosts stories={stories}>
            {({ analyses }) => (
              <TrendAnalyzer analyses={analyses}>
                {(report) => (
                  <PGEditor content={report}>
                    {(editedReport) => (
                      <PGTweetWriter
                        context={editedReport}
                        prompt="Summarize the HN trends in a tweet"
                      >
                        {(tweet) => ({ report: editedReport, tweet })}
                      </PGTweetWriter>
                    )}
                  </PGEditor>
                )}
              </TrendAnalyzer>
            )}
          </AnalyzeHNPosts>
        )}
      </HNCollector>
    )}
  </OpenAIProvider>
));

Every layer of this has strong typing, except for the leaf that returns values to the workflow:

{(tweet) => ({ report: editedReport, tweet })}

Typescript resolves this as an unknown, and doesn't validate that this return matches the HNAnalyzerWorkflowOutput return type that is declared. So if you change the shape of that return, you won't get a compiler error, but could get a runtime error.

Fundamentally, this limitation is due to microsoft/TypeScript#21699

We believe we can improve this by implementing a typescript compiler extension as described here: #100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant