avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

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

Closed jonahsnider closed 4 years ago

jonahsnider commented 4 years ago

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

Environment

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

Silic0nS0ldier commented 4 years ago

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;
}
novemberborn commented 4 years ago

See the discussion in https://github.com/avajs/ava/issues/2212. A fix is in progress at https://github.com/avajs/ava/pull/2308.

novemberborn commented 4 years ago

Oh wait — reading more closely, is this something that started happening with TypeScript 3.7.4?

jonahsnider commented 4 years ago

Issue is still present with TypeScript v3.7.3 and v3.7.2.

novemberborn commented 4 years ago

I'd be happy to ship a 2.4.1 release if necessary, but I can't tell from the feedback here whether this is something that stopped working recently or has always been a problem. I haven't encountered it myself.

@znorman-harris*, do you have any insight here?

jonahsnider commented 4 years ago

Perhaps this had something to do with the typings for Node @types/node and not the TypeScript compiler?

novemberborn commented 4 years ago

Perhaps this had something to do with the typings for Node @types/node and not the TypeScript compiler?

Yes, maybe. Hopefully folks can work around that by pinning an older version.

sramam commented 4 years ago

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.

novemberborn commented 4 years ago

OK so it may indeed be @types/node. That's not the best fix, but it looks like this can be worked around.

AVA 3 beta will be out soon (unofficially, I'm too tired to write the release notes) which does away with this symbol type altogether.

znorman-harris commented 4 years ago

@novemberborn this was something that came up recently for me. I remember seeing it a while back, but dismissed it when it didn't reappear.

Considering there is a workaround I'm good and can wait until the next release!

novemberborn commented 4 years ago

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 😉

SephReed commented 4 years ago

I'm getting this error as well. Having a really hard time getting tsconfig { "exclude": [] } syntax to ignore my test files.

Should this issue be opened again? It seems it's not yet really resolved.

SephReed commented 4 years ago

Got a fix for now:

tsconfig.json:

{
  "exclude": ["**/__tests/*", "**/testing/*"],
  "include": ["./src"],
  "compilerOptions": {
     // code omitted....
  }
}
tjmosia commented 4 years ago

The issue actually lies with Typescript here... The typescript file where global Symbol variable and SymbolConstructor is declared doesn't have observable as one of it's properties. It feels kinda crappy modifying that file...

novemberborn commented 4 years ago

@tjmosia this has been resolved with AVA 3.