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

Fixes for TS type issues introduced in racer@2.2.0 / TS 5.5 #313

Merged
merged 3 commits into from
Jul 22, 2024

Conversation

ericyhwang
Copy link
Contributor

racer@2.2.0 introduced a handful of TypeScript errors when used with Derby.

Fix Derby app.use(plugin, options) TS error

When registering a Derby app plugin with strict types, racer@2.2.0 introduced errors like this:

Argument of type '(app: App, appName: string) => void' is not assignable to parameter of type '(arg0: unknown, options?: unknown) => void'.
  Types of parameters 'app' and 'arg0' are incompatible.
    Type 'unknown' is not assignable to type 'App'.

Derby utilizes the plugin use function from Racer, which in racer@2.2.0 switched the plugin function from implicit anys to explicit unknowns.

This changes the use function to use inferred generic types, which allows proper verification that the plugin uses the correct options and this if specified.

TS 5.5 related updates

Updates to have Racer work properly with TS 5.5:

  • The triple-slash reference directives used to load types for server-only model methods are no longer automatically included in the output d.ts files.
    • This was causing TS errors like Property 'createConnection' does not exist on type 'RootModel'. in Derby.
    • We need to add preserve="true" to tell the compiler to include them.
  • Remove noImplicitUseStrict compiler flag, since TS 5.5 no longer supports it
    • This means the output JS files with each have a "use strict"; at the top
  • Update typedoc deps for TS 5.5 compatibility

The TypeScript dependency was using ^5.1, which was automatically picking up new major TypeScript versions. TS doesn't use semver, and each +0.1 is treated as a major version.

This switches to using a ~ dependency so Racer wont pick up major TS releases automatically.

…ly typed plugin functions

Resolves error introduced in racer@2.2.0 where Derby app.use plugins had TS compile errors
… since TypeScript doesn't use semver

- Remove noImplicitUseStrict compiler flag, since TS 5.5 no longer supports it

- Put preserve="true" on triple-slash reference directives used to load types for server-only model methods, since TS 5.5 strips the directives without the new preserve attribute
@ericyhwang ericyhwang merged commit a20e9d2 into master Jul 22, 2024
9 checks passed
@ericyhwang ericyhwang deleted the fix-racer-2.2.0 branch July 22, 2024 21:50
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.

1 participant