Describe the bug
A clear and concise description of what the bug is.
Source code at src/utils/utils.node.ts#L34 and src/utils/utils.node.ts#L93 has type overloads for Node.js v12.
To Reproduce
Steps to reproduce the behavior:
tscnode_modules/@azure/storage-blob/src/utils/utils.node.ts:34:17 - error TS2769: No overload matches this call.
Overload 1 of 4, '(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
Overload 2 of 4, '(str: string, encoding?: BufferEncoding): Buffer', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'BufferEncoding'.
34 chunk = Buffer.from(chunk, encoding);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@azure/storage-blob/src/utils/utils.node.ts:93:17 - error TS2769: No overload matches this call.
Overload 1 of 4, '(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
Overload 2 of 4, '(str: string, encoding?: BufferEncoding): Buffer', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'BufferEncoding'.
93 chunk = Buffer.from(chunk, encoding);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 2 error(s).
Expected behavior
Typescript does not throw error.
Thanks for reporting @galkin
@XiaoningLiu I believe the same issue will affect storage v12 as well right?
We have pipelines running against node v12 I doubt I is a problem. Likely node types needs update at the same time too?
@jeremymeng, yes. Common expectation is equal typing and Node.js versions.
Greetings @ramya-rao-a @XiaoningLiu @HarshaNalluru
Do you have any updates?
@galkin can you say more about what you're trying to do? Are you attempting to build the library with the Node 12 types, or are you trying to consume the library from npm with Node 12 types?
If the latter, it should work with the Storage v12 package we just released.
If the former, we are deliberately using Node v8 types. Libraries should generally use the types that correspond to the lowest version of Node they support. This ensures that we don't inadvertently use features that aren't available in later versions of Node.
FWIW, the type error is a result of Buffer.from changing from (string, string) in the v8 types to (string, BufferEncoding) in v12, where BufferEncoding is a union of string literal types corresponding to the allowable encoding options. The underlying runtime semantics didn't change. The new types are slightly safer and better though 馃榾
@bterlson,
1) I updated to v12.0.0 at last week. There are the same problem. I changed issue name.
2) Right now my I fixing that by adding postinstall script what add lines as the opened pull request #6078
3) I'm totally agree with you regarding reasons of the bug. The problem is related to typescript build time with v12 Node.js types only. It's not related to run time or building with Node.js types v10 or early.
4) If you think Node.js binding should be less strict, let discuss that or let open issue here
@galkin are you attempting to build the storage library yourself, or are you trying to consume the storage library from npm?
@bterlson, we use npm, not building. My mistake, I checked that file with the problem is exist at v12, it was automatically changed by postinstall script. But I didn't check is that problem is unreproducible.
So we didn't have the problem.
@galkin no problem! Happy to help if you run into more issues. Also, let us know what you think of the new storage libraries 馃榿
@azure/storage-blob v12 has awesome API. We migrated from v10 at the first day and it was pleasure to do this. Thank you for your work!
Most helpful comment
@azure/storage-blobv12 has awesome API. We migrated from v10 at the first day and it was pleasure to do this. Thank you for your work!