microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.27k stars 12.39k forks source link

Error: Class incorrectly implements interface with no reason specified #1734

Closed jvilk closed 9 years ago

jvilk commented 9 years ago

I'm getting the following compiler error using TypeScript 1.4.1:

error TS2420: Class 'WorkerFS' incorrectly implements interface 'FileSystem'.

Unfortunately, TypeScript does not tell me what property or method is incorrectly implemented/specified, if any. Is this a bug in the compiler?

The relevant code can be checked out of the webworker branch of my BrowserFS repository.

Compiler command:

tsc --module amd src/backend/workerfs.ts

If that's too much code to work through, I can see if I can work it into a smaller test case...

Thanks in advance!

danquirk commented 9 years ago

It should certainly be telling you the offending member.

DanielRosenwasser commented 9 years ago

Offhandedly, it seems like you're missing diskSpace, you may have misspelled supportsSync as supportsSynch in file_system (or vice versa).

A couple of the *Sync methods are missing, for which you'll need to implement in WorkerFS and throw an exception in them, or make them optional in the FileSystem interface.

There might be more (or I might be wrong entirely) but that's it at a glance. If this fixes your problem, don't close the issue.

RyanCavanaugh commented 9 years ago

Related to #933 perhaps?

RyanCavanaugh commented 9 years ago

Here's an example of a way to reproduce the issue (might not be the same as the linked repo, but illustrates the point):

interface FileSystem {
  read: number;
}

function fn(s: WorkerFS): void;
function fn(s: FileSystem): void;
function fn(s: FileSystem|WorkerFS) { }

class WorkerFS implements FileSystem {
  read: string;
}

This emits only the following error (with no details):

a.ts(10,7): error TS2420: Class 'WorkerFS' incorrectly implements interface 'FileSystem'.
jvilk commented 9 years ago

Wow, didn't take long for all of you to look into this! Awesome.

...you may have misspelled supportsSync as supportsSynch in file_system (or vice versa).

Yup, that was the only thing I was missing. The diskSpace and *Sync methods have default implementations in the BaseFileSystem class that I am extending. (It's supportsSynch to disambiguate between synchronous file system operations and the sync method.)

Hopefully I won't encounter this bug again until it's fixed, since it's rather frustrating to have an unactionable error when you have a lot of methods in an interface. Best of luck with the fix!

hessryanm commented 8 years ago

I'm still having this problem, even though it's marked as fixed.

Please see Gist: https://gist.github.com/hessryanm/177b0cada8c51516371e

Error is: models/Card.ts(13,14): error TS2420: Class 'Card' incorrectly implements interface 'ICard'.

mhegazy commented 8 years ago

@hessryanm filed #5757 to track this issue.