Workflow Testing Framework violates typescript checks? @temporalio/worker/lib/connection").NativeConnection is not assignable to type @temporalio/testing/node_modules/@temporalio/worker/lib/connection").NativeConnection

Hello, I’m trying to run a simple workflow test and I find that there are linting and typescript errors when using the @temporalio/testing module.

So far, I’m faced with two issues and this post is about the first issue. The second issue is Workflow Testing Framework violates typescript checks? "duplicate name 'ActivityHeartbeat' in Namespace coresdk"

TS error: @temporalio/worker/lib/connection").NativeConnection is not assignable to type @temporalio/testing/node_modules/@temporalio/worker/lib/connection").NativeConnection

This error shows when using the WorkerOptions from @temporalio/testing, the result of augmentWorkerOptions() for the Worker.create(workerOptions) call.

const workflowCoverage = new WorkflowCoverage();
const workerOptions = workflowCoverage.augmentWorkerOptions({
      connection: nativeConnection,
      taskQueue: 'test',
      workflowsPath: require.resolve('src/workflows/ev-charger/installation-workflow'),
      activities: {
        getNextProvider: () => serviceProviderData,
      },
    });
const worker = await Worker.create(workerOptions);

I worked around this by importing WorkerOptions from the same package…

import { Worker, WorkerOptions } from '@temporalio/worker';

…and declaring the testing instance version of WorkerOptions as the worker’s version of WorkerOptions.

const worker = await Worker.create(workerOptions as WorkerOptions);

The gist seems to be: the testing module has the node_module dependency to the same NativeConnection that is in @temporalio/worker/lib/connection so even though the class is the same, typescript doesn’t recognize that it is so.

Thank you for taking a look at this!

You have multiple copies of the @temporalio/worker package.

Try running npm why @temporalio/worker

Yes, I recognized that as well but the @temporalio/worker package is referenced in two other temporal packages:
@temporalio/nyc-test-coverage/node_modules/@temporalio/worker
@temporalio/testing/node_modules/@temporalio/worker

npm why @temporalio/worker
@temporalio/worker@1.8.0
node_modules/@temporalio/nyc-test-coverage/node_modules/@temporalio/worker
  @temporalio/worker@"1.8.0" from @temporalio/nyc-test-coverage@1.8.0
  node_modules/@temporalio/nyc-test-coverage
    @temporalio/nyc-test-coverage@"^1.8.0" from the root project

@temporalio/worker@1.8.0
node_modules/@temporalio/testing/node_modules/@temporalio/worker
  @temporalio/worker@"1.8.0" from @temporalio/testing@1.8.0
  node_modules/@temporalio/testing
    @temporalio/testing@"^1.8.0" from the root project

@temporalio/worker@1.7.1
node_modules/@temporalio/worker
  @temporalio/worker@"1.7.1" from the root project

Is there a way to let typescript know that it’s the same code? How can I avoid the errors?
Thank you @jwatkins!

@jwatkins, looks like I ran right into an in-between upgrade state. Some of my temporal packages’ latest version was 1.7.1 while others where already on 1.8.0 (or 1.8.1).

I see that @temporalio/client was upgraded 5 days ago.
image

When I installed, I hit right before that but after @temporalio/nyc-test-coverage and @temporalio/testing was upgraded to 1.8.0

Upgraded all to 1.8.1 and the errors are gone.