patriksimek / vm2

Advanced vm/sandbox for Node.js
MIT License
3.86k stars 293 forks source link

Typescript compilation errors in release 3.9.12 #493

Closed mozrat closed 1 year ago

mozrat commented 1 year ago

I believe that 3.9.12 does not compile properly with typescript 4.7.4


node_modules/vm2/index.d.ts:38:40 - error TS1176: Interface declaration cannot have 'implements' clause.

38 export interface VMFileSystemInterface implements VMFS, VMPath {
                                          ~~~~~~~~~~

node_modules/vm2/index.d.ts:46:14 - error TS2420: Class 'VMFileSystem' incorrectly implements interface 'VMFileSystemInterface'.
  Property 'isSeparator' is missing in type 'VMFileSystem' but required in type 'VMFileSystemInterface'.

46 export class VMFileSystem implements VMFileSystemInterface {
                ~~~~~~~~~~~~

  node_modules/vm2/index.d.ts:40:2
    40  isSeparator(char: string): boolean;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'isSeparator' is declared here.

Is there now a minimum typescript version that you support, and could that be documented

Thanks for a fantastic library.

XmiliaH commented 1 year ago

This seems like an fault on our side.

Could you try and replace the new definitions with the following version and report back.

/**
 * Interface for nodes fs module
 */
export interface VMFS {
  /** Implements fs.statSync */
  statSync: typeof fs.statSync;
  /** Implements fs.readFileSync */
  readFileSync: typeof fs.readFileSync;
}

/**
 * Interface for nodes path module
 */
export interface VMPath {
  /** Implements path.resolve */
  resolve: typeof pa.resolve;
  /** Implements path.isAbsolute */
  isAbsolute: typeof pa.isAbsolute;
  /** Implements path.join */
  join: typeof pa.join;
  /** Implements path.basename */
  basename: typeof pa.basename;
  /** Implements path.dirname */
  dirname: typeof pa.dirname;
}

/**
 * Custom file system which abstracts functions from node's fs and path modules.
 */
export interface VMFileSystemInterface extends VMFS, VMPath {
  /** Implements (sep) => sep === path.sep */
  isSeparator(char: string): boolean;
}

/**
 * Implementation of a default file system.
 */
export class VMFileSystem implements VMFileSystemInterface {
  constructor(options?: { fs?: VMFS, path?: VMPath });
  /** Implements fs.statSync */
  statSync: typeof fs.statSync;
  /** Implements fs.readFileSync */
  readFileSync: typeof fs.readFileSync;
  /** Implements path.resolve */
  resolve: typeof pa.resolve;
  /** Implements path.isAbsolute */
  isAbsolute: typeof pa.isAbsolute;
  /** Implements path.join */
  join: typeof pa.join;
  /** Implements path.basename */
  basename: typeof pa.basename;
  /** Implements path.dirname */
  dirname: typeof pa.dirname;
  /** Implements (sep) => sep === path.sep */
  isSeparator(char: string): boolean;
}
nealol commented 1 year ago

I can confirm that the updated typescript definitions fix the compilation issue for me.

XmiliaH commented 1 year ago

Should be fixed now. If anyone knows a GitHub action that can be used to check the index.d.ts file please let me know.