Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed library #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Typed library #29

wants to merge 2 commits into from

Conversation

r4zendev
Copy link

Hello, please review the typings I wrote and approve if valid.

Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/loader.d.ts Outdated
import { BaseOptions } from 'vm';
import { MetaScript } from './vm';

export declare const readScript: (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export declare const readScript: (
export declare {
function readScript(

lib/vm.d.ts Outdated
Comment on lines 5 to 18
type VMCtxNodeKeys =
| 'Buffer'
| 'console'
| 'queueMicrotask'
| 'setTimeout'
| 'setImmediate'
| 'setInterval'
| 'clearTimeout'
| 'clearImmediate'
| 'clearInterval';

type VMContextNodeTypes = {
[key in VMCtxNodeKeys]: NodeJS.Global[key];
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to specify this certain list

lib/vm.d.ts Outdated
[key in VMCtxNodeKeys]: NodeJS.Global[key];
};

type VMContextLibDOMTypes = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use interfaces instead of types

lib/vm.d.ts Outdated
constructor(
name: string,
src: string,
options?: vm.ScriptOptions & { context: vm.Context }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need new interface for options

lib/vm.d.ts Outdated
Comment on lines 47 to 51
export declare const createScript: (
name: string,
src: string,
options?: vm.ScriptOptions & { context: vm.Context }
) => MetaScript;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export declare const createScript: (
name: string,
src: string,
options?: vm.ScriptOptions & { context: vm.Context }
) => MetaScript;
function createScript(name: string, src: string, options?: MetaOptions): MetaScript;

@r4zendev
Copy link
Author

Tried replacing the parts you emphasized on. May I ask why would it be necessary to stick with interfaces? I was pretty concerned that the "type" structure is more powerful until now.
Also, I didn't manage to get proper use of node types installation, hence still had to require the options interface.
Thanks for reviewing my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants