Definitelytyped: [@types/fs-extra] Errors with @types/node@10

Created on 21 May 2020  路  8Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [x] I tried using the @types/xxxx package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [x] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @peterblazejewicz @ffflorian

The types for fs-extra reference some members from @types/node directly that are only present in Node 12+. This causes compilation to fail when combined with @types/node@10, which should work because fs-extra supports Node 10. The problem is that since fs-extra re-exports members from the native fs, those have been copied into @types/fs-extra. I believe it would be better to not do that manually and instead if possible re-export typeof import('fs') so that it picks up whatever is in the environment. Unfortunately I don't have time to work on this myself.

node_modules/@types/fs-extra/index.d.ts:188:87 - error TS2694: Namespace '"fs"' has no exported member 'Dir'.

188 export function opendir(path: string, cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void): void;
                                                                                          ~~~

node_modules/@types/fs-extra/index.d.ts:191:17 - error TS2694: Namespace '"fs"' has no exported member 'OpenDirOptions'.

191     options: fs.OpenDirOptions,
                    ~~~~~~~~~~~~~~

node_modules/@types/fs-extra/index.d.ts:192:53 - error TS2694: Namespace '"fs"' has no exported member 'Dir'.

192     cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void,
                                                        ~~~

node_modules/@types/fs-extra/index.d.ts:194:52 - error TS2694: Namespace '"fs"' has no exported member 'OpenDirOptions'.

194 export function opendir(path: string, options?: fs.OpenDirOptions): Promise<fs.Dir>;
                                                       ~~~~~~~~~~~~~~

node_modules/@types/fs-extra/index.d.ts:194:80 - error TS2694: Namespace '"fs"' has no exported member 'Dir'.

194 export function opendir(path: string, options?: fs.OpenDirOptions): Promise<fs.Dir>;
                                                                                   ~~~

node_modules/@types/fs-extra/index.d.ts:265:52 - error TS2694: Namespace 'NodeJS' has no exported member 'ArrayBufferView'.

265 export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], position: number, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
                                                       ~~~~~~~~~~~~~~~

node_modules/@types/fs-extra/index.d.ts:265:167 - error TS2694: Namespace 'NodeJS' has no exported member 'ArrayBufferView'.

265 export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], position: number, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
                                                                                                                                                                          ~~~~~~~~~~~~~~~

node_modules/@types/fs-extra/index.d.ts:266:52 - error TS2694: Namespace 'NodeJS' has no exported member 'ArrayBufferView'.

266 export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
                                                       ~~~~~~~~~~~~~~~

node_modules/@types/fs-extra/index.d.ts:266:149 - error TS2694: Namespace 'NodeJS' has no exported member 'ArrayBufferView'.

266 export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
                                                                                                                                                        ~~~~~~~~~~~~~~~

node_modules/@types/fs-extra/index.d.ts:267:52 - error TS2694: Namespace 'NodeJS' has no exported member 'ArrayBufferView'.

267 export function writev(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number): Promise<WritevResult>;
                                                       ~~~~~~~~~~~~~~~

Most helpful comment

@frangio I can reproduce the error. Unfortunately I don't have a solution for that beside upgrading @types/node to 14.x or downgrading @types/fs-extra to 8.1.0.

We are already exporting * from 'fs', but since fs-extra adds a promisified version of opendir() and writev(), these need to be reflected in the types. Since there is no conditional types export yet AFAIK, there is not much we can do in my opinion.

All 8 comments

@frangio

The types for fs-extra reference some members from @types/node directly that are only present in Node 12+.

Which members are that? Can you post an error message or something like that?

I forgot to specify, I'm sorry. I've edited the original post with the error messages.

Same issue here.

@peterblazejewicz can you take a look?

@frangio I can reproduce the error. Unfortunately I don't have a solution for that beside upgrading @types/node to 14.x or downgrading @types/fs-extra to 8.1.0.

We are already exporting * from 'fs', but since fs-extra adds a promisified version of opendir() and writev(), these need to be reflected in the types. Since there is no conditional types export yet AFAIK, there is not much we can do in my opinion.

The "forward declarations" feature in TypeScript's 4.0 roadmap may be of use here.

Alternatively, I've built a package which is similar to fs-extra in that it re-exports promisified Node.js functions and solves the issue using mapped types. The same approach could be used here, but it would increase the complexity of the type definitions.

https://github.com/frangio/promisified/blob/a868d31d801237f61f60aa026bb7303fd8dfa3cb/internal.d.ts#L5-L7

@peterblazejewicz can you take a look?
Yes, sorry for delay. I can see the problem, not sure myself how to properly manage different iterations of node versions and types

For some reason if I npm install @types/node the package manager install a v10.10 version of node??? That's odd. So I forced npm to install the latest version of @types/[email protected] and that seemed to fix it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tyv picture tyv  路  3Comments

jrmcdona picture jrmcdona  路  3Comments

JWT
svipas picture svipas  路  3Comments

variousauthors picture variousauthors  路  3Comments

demisx picture demisx  路  3Comments