ava: Typings error TS2339: Property 'observable' does not exist on type 'SymbolConstructor'

Description

When compiling with TypeScript there is a typings error which makes the TypeScript compiler exit with exit code 2. The code still gets compiled but my build CI fails because of the exit code. This happens on the latest AVA version if AVA is being compiled at all by TSC.

Error Message & Stack Trace

node_modules/ava/index.d.ts:5:10 - error TS2339: Property 'observable' does not exist on type 'SymbolConstructor'
5	[Symbol.observable](): ObservableLike;

Command-Line Arguments

Run this to compile my example repo.

tsc index.ts

Relevant Links

  • Minimal repo is here, just clone, npm install, and run tsc index.ts

Environment

TypeScript v3.7.4 Node.js v12.14.0 linux 4.4.0-18362-Microsoft AVA v2.4.0 npm v6.13.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

npm i -D -E ava@next will give you the next release, but I haven’t yet documented the breaking changes so use at your own peril 😉

I’ve also experienced this issue. Having looked into closed tickets, this appears to have been an issue that was previously resolved.

A temporary work-around is to put this into a general “global types” file. With some tweaks, it can be placed directly in test files as well.

declare interface SymbolConstructor {
    readonly observable: symbol;
}

Got a fix for now:

tsconfig.json:

{
  "exclude": ["**/__tests/*", "**/testing/*"],
  "include": ["./src"],
  "compilerOptions": {
     // code omitted....
  }
}

I can verify that this happens with

node @ v12.7.0
ava @ 2.4.0
@types/node @ 13.1.4

But does not at

node @ v12.7.0
ava @ 2.4.0
@types/node @ 12.12.24

It seems to be a @types/node@v13.0 update

I don’t understand this change to make sense of what is going on, but it seems adding import Symbol_observable from 'symbol-observable'; to avajs/index.d.ts resolves the tsc error.

For my case it seems to work, not sure if that is however a proper fix.