node-argon2 icon indicating copy to clipboard operation
node-argon2 copied to clipboard

Type regression between v0.31.2 and v0.40.1

Open Bluzzi opened this issue 9 months ago • 5 comments

Welcome to the issues section if it's your first time!

Before creating an issue, please be sure to:

  • [x] Checkout to the latest version, including submodules
  • [x] Try to find an isolated way to reproduce the behavior
  • [x] Fill in all the blanks in the most specific way you can

Steps to reproduce

import type { Options } from "argon2";

export const options: Options = {
  hashLength: 32,
  saltLength: 16, // <--- Object literal may only specify known properties, and 'saltLength' does not exist in type 'Options'.ts(2353)
  timeCost: 3,
  parallelism: 2
};

Expected behaviour

The “saltLength” field must be present in the Options type, as it was in version 0.31.2 (see the argon2.d.ts file).

Actual behaviour

The “saltLength” field is not present in the Options type, see the argon2.d.cts file in version 0.40.1.

Bluzzi avatar Apr 27 '24 19:04 Bluzzi

There are other differences between the two versions:

  • saltLength no longer exists (original issue)
  • the type of salt is any | undefined instead of Buffer | undefined
  • the type of associatedData is any | undefined instead of Buffer | undefined
  • the type of secret is any | undefined instead of Buffer | undefined
  • ~~raw is no longer present - but I see that it is added dynamically when typing the function hash~~
// v0.40.1
export type Options = {
    hashLength?: number | undefined;
    timeCost?: number | undefined;
    memoryCost?: number | undefined;
    parallelism?: number | undefined;
    type?: 0 | 2 | 1 | undefined;
    version?: number | undefined;
    salt?: any;
    associatedData?: any;
    secret?: any;
};

// v0.31.2
export interface Options {
  hashLength?: number;
  timeCost?: number;
  memoryCost?: number;
  parallelism?: number;
  type?: typeof argon2d | typeof argon2i | typeof argon2id;
  version?: number;
  salt?: Buffer;
  saltLength?: number;
  raw?: boolean;
  secret?: Buffer;
  associatedData?: Buffer;
}

Bluzzi avatar Apr 27 '24 19:04 Bluzzi

No one has said anything?. They just changed the parameters without changing the doc?

Jendorski avatar May 01 '24 17:05 Jendorski

No one has said anything?. They just changed the parameters without changing the doc?

The parameter was not changed, there is a bug in Typescript when generating object types from JSDoc that I still didn't figure out how to fix, since it works as expected on my machine, in an isolated container

ranisalt avatar May 01 '24 20:05 ranisalt

I just republished and Typescript is still generating incorrect types.

ranisalt avatar May 25 '24 21:05 ranisalt

This remains an issue and is blocking us from upgrading from 0.31.2 to the latest version.

Tested with 0.40.3

Is there anything we can do to help with this?

erichkuba avatar Jun 20 '24 04:06 erichkuba

v0.41.1 was published with proper types! The culprit was missing install before generating the types, which was causing @types/node to be missing - Typescript does not know what a Buffer is without it, so it output any

image

ranisalt avatar Aug 31 '24 22:08 ranisalt