Skip to content

[Suggestion]: Add types to React compiler debugging example #8245

@maurer2

Description

@maurer2

Summary

Hello I noticed that the examples on the debugging page (https://react.dev/reference/react-compiler/logger#basic-logging) for the compiler don’t include TypeScript types. It might be helpful to add them for the basic example like so

import type { Logger } from 'babel-plugin-react-compiler';

{
...
  logger: {
    logEvent(filename, event) {
      switch (event.kind) {
        case 'CompileSuccess': {
          console.log(`✅ Compiled: ${filename}`);
          break;
        }
        case 'CompileError': {
          console.log(`❌ Skipped: ${filename}`);
          break;
        }
        default: {}
      }
    }
  } satisfies Logger,
...
}

Using satisfies Logger ensures that logEvent(filename, event) is properly typed without needing to manually annotate the parameters.

Cheers

Page

Compiler debugging docs

Details

Adding types would be helpful for IntelliSense and would also help avoid potential errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions