automerge / pushpin

A collaborative corkboard app
BSD 3-Clause "New" or "Revised" License
636 stars 54 forks source link

Argument of type '({ done, value }: { done: boolean; value: any; }) => void' is not assignable to parameter of type '(value: ReadableStreamReadResult<any>) => void | PromiseLike<void>' #395

Closed raphael10-collab closed 3 years ago

raphael10-collab commented 4 years ago

I'm transposing/translating pushpin into electron-vue

nano src/services/p2p/hyperfile.ts :

import { RepoFrontend, HyperfileUrl } from 'hypermerge'
import { Readable } from 'stream'
import { Header } from 'hypermerge/dist/FileStore'
import { FILE_SERVER_PATH } from './constants'
import { toNodeReadable } from '@/NodeReadable'

const repo = new RepoFrontend()
repo.files.setServerPath(FILE_SERVER_PATH)

nano src/NodeReadable.ts :

import { Readable } from 'stream'

export function toNodeReadable(stream: ReadableStream): Readable {
  return new NodeReadable(stream, {})
}

export class NodeReadable extends Readable {
  private webStream: ReadableStream
  private reader: ReadableStreamDefaultReader
  private reading: boolean

  constructor(webStream: ReadableStream, options: any) {
    super(options)
    this.webStream = webStream
    this.reader = webStream.getReader()
    this.reading = false
  }

  _read(size: number) {
    if (this.reading) {
      return
    }
    this.reading = true
    this.doRead(size)
  }

  doRead(size: number) {
    this.reader
      .read()
      .then(({ done, value }: { done: boolean; value: any }) => {
        if (done) {
          this.push(null)
          return
        }
        if (this.push(value)) {
          this.doRead(size)
          return
        }
        this.reading = false
      })
      .catch((e) => {
        this.emit('error', e)
      })
  }
}

Which seems ok.... (I didn't change anything) But I get this error:

ERROR in /home/marco/webMatters/electronMatters/GGC-Electron/src/NodeReadable.ts(30,13): 30:13 Argument of type '({ done, value }: { done: boolean; value: any; }) => void' is not assignable to parameter of type '(value:
ReadableStreamReadResult) => void | PromiseLike'. Types of parameters '__0' and 'value' are incompatible. Type 'ReadableStreamReadResult' is not assignable to type '{ done: boolean; value: any; }'. Type 'ReadableStreamReadDoneResult' is not assignable to type '{ done: boolean; value: any; }'. Property 'value' is optional in type 'ReadableStreamReadDoneResult' but required in type '{ done: boolean; value: any; }'. 28 | this.reader 29 | .read()

30 | .then(({ done, value }: { done: boolean; value: any }) => { | ^ 31 | if (done) { 32 | this.push(null) 33 | return

This is tsconfig.json :

{ // https://www.typescriptlang.org/tsconfig
  "compilerOptions": {
    "target": "es2019",
    "module": "es2020", 
    "strict": true,
    "noImplicitAny": false,
    "noFallthroughCasesInSwitch": true, 
    "lib": ["es2015", "es2017", "es2019", "es2020", "dom", "webworker"], 
    "jsx": "react", 
    "pretty": true,
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "mocha",
      "chai"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
   "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}