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

Which types to use for objects - so many any types #87

Open
cinderblock opened this issue Apr 19, 2023 · 1 comment
Open

Which types to use for objects - so many any types #87

cinderblock opened this issue Apr 19, 2023 · 1 comment

Comments

@cinderblock
Copy link

cinderblock commented Apr 19, 2023

I'm trying to use this package as described in the readme:

import SSH2Promise from 'ssh2-promise';

const connection = new SSH2Promise(opts);

Some functions, like .sftp(), are typed properly and chained calls work as expected:

connection.sftp().changeMode(typesOnArguments, workAsExpected);

But other functions get any types inferred.

const s = connection.shell(opts);

Both opts and s have any type according to my TypeScript language server.

Looking at the source code, I see that sftp() has a type SFTP in SSH2Promise class type, and many of the types, and extends BaseSSH2Promise which has mostly any types.
I also see the SSHConnection type which does seem to have the more strict types that I'd like to use, but it's not clear how to use that class "correctly".

If feels like much of the desired types are in the source code but that they're just not quite linked to each other properly. Do we need another round of #55? I see some other discussions of this issue specifically in #12 but that has been closed and merged. Should these issues still be happening or am I doing something stupid? Or maybe the readme should be updated to suggest using new SSH2Promise.SSH() instead?

But using SSH2Promise.SSH doesn't have the same Promise versions of the sftp() commands...

@cinderblock
Copy link
Author

cinderblock commented Apr 25, 2023

Adding to this confusion... the types for SSH2Promise.shell() seem incomplete.

TypeScript server thinks it only takes 1 argument of type any, from the BaseSSH2Promise type, but it the base implementation takes 2 arguments. It looks like the implementation here doesn't allow using the second argument:

shell(options: ShellOptions = {}): Promise<ClientChannel> {
return this.connect().then(() => {
return new Promise<ClientChannel>((resolve, reject) => {
this.sshConnection.shell(options, (err, stream) => err ? reject(err) : resolve(stream));
});
})
}

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

No branches or pull requests

1 participant