bindCallback
and bindNodeCallback
can be complicated with TypeScript, since it all depends on how TypeScript indicates the parameters of the function.
, , , , , : . , :
const n: number = Observable.bindNodeCallback(fs.readFile);
:
Type '(v1: string) => Observable<Buffer>' is not assignable to type 'number'.
, , TypeScript readFile
.
, , . , :
const n: number = Observable.bindNodeCallback((
path: string,
encoding: string,
callback: (error: Error, buffer: Buffer) => void
) => fs.readFile(path, encoding, callback));
:
Type '(v1: string, v2: string) => Observable<Buffer>' is not assignable to type 'number'.
, :
let readFileAsObservable = Observable.bindNodeCallback((
path: string,
encoding: string,
callback: (error: Error, buffer: Buffer) => void
) => fs.readFile(path, encoding, callback));
let result = readFileAsObservable('./package.json', 'utf8');
result.subscribe(
buffer => console.log(buffer.toString()),
error => console.error(error)
);