node: [fix] node buffers have a constructor property#28900
node: [fix] node buffers have a constructor property#28900jessetrinity merged 2 commits intoDefinitelyTyped:masterfrom ljharb:buffer_constructor
node: [fix] node buffers have a constructor property#28900Conversation
|
@ljharb Thank you for submitting this PR! 🔔 @parambirs @tellnes @WilcoBakker @octo-sniffle @smac89 @Flarna @mwiktorczyk @wwwy3y3 @DeividasBakanas @kjin @alvis @eps1lon @Hannes-Magnusson-CK @jkomyno @ajafff @hoo29 @n-e @BrunoScheufler @mohsen1 @KSXGitHub @a-tarasyuk @islishude @r3nya @eyqs @ZaneHannanAU @ThomasdenH @matthieusieben - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
@ljharb The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
Looks like the node types prior to v9 lack types for the NodeBuffer constructor itself - I'll revert those, and only include the v9+ type fix. |
|
I'm not sure what this change is needed for. What's wrong with the |
|
@Flarna i have a place where i do I’ll try to add a test. |
|
@ljharb With latest NodeJs I mean the file |
|
Because if i do that, bundlers include an entire Buffer polyfill - see ljharb/qs#39. As for the type, for any builtin T besides Function, |
|
ok understood.
Seems so yes, see microsoft/TypeScript#3841 |
|
In that case, do you suggest a different approach? This is a pretty basic part of JS to have been mistyped for this long :-/ |
|
I don't have a different approach. |
Flarna
left a comment
There was a problem hiding this comment.
Please adapt also latest NodeJs typings (file types\node\index.d.ts)
|
@Flarna thanks, updated (i missed it because i assumed there'd be a v10 folder) |
|
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
|
@ljharb Did you still want to add a test to this? |
|
Why we have TypeScript enforces But Node "class"es are not real classes and are just plain functions. We have to decide if we want to use |
|
@jessetrinity oh right, i'd forgotten - is there an easy way to just run the tests for this one package without having to run them for the entire repo? |
Note that JS doesn't have any sort of "real classes", just |
|
TypeScript throws an error for calling classes without Currently @Andy-MS |
|
In that case then anything not declared with |
|
Even if that did work, I think the simplicity of declaring something as a |
|
@Andy-MS i'd say if it worked, then typing it to include that would be critical; if it doesn't work, then clearly it's acting as a |
|
@jessetrinity fwiw |
I think mostly because no one issues a PR to improve this. I can remember several PRs to change this and that |
NodeJs doc tells it's a class. |
|
@ljharb Node 10 should be fine. Normally you can run tests from types/foo but in the case of Node you should run the whole things. Any details on how it is failing? I will have to ask around about Mac. |
|
@jessetrinity compilation errors: Details$HOME/.node-gyp/10.10.0/include/node/openssl/ossl_typ.h:107:16
: note: forward declaration of 'struct dsa_st'
typedef struct dsa_st DSA;
^
../vendor/libssh2/src/openssl.c:133:14: error: incomplete definition of type 'struct dsa_st'
(*dsactx)->q = BN_new();
~~~~~~~~~^
$HOME/.node-gyp/10.10.0/include/node/openssl/ossl_typ.h:107:16: note: forward declaration of 'struct dsa_st'
typedef struct dsa_st DSA;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/libssh2/vendor/libssh2/src/openssl.o] Error 1
gyp
ERR! build error
gyp
ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack
at ChildProcess.onExit ($HOME/.nvm/versions/node/v10.10.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR!
stack at ChildProcess.emit (events.js:182:13)
gyp
ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp
ERR! System Darwin 17.7.0
gyp
ERR! command "$HOME/.nvm/versions/node/v10.10.0/bin/node" "$HOME/.nvm/versions/node/v10.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=$HOME/airlab/repos/DefinitelyTyped/node_modules/nodegit/build/Release/nodegit.node" "--module_name=nodegit" "--module_path=$HOME/airlab/repos/DefinitelyTyped/node_modules/nodegit/build/Release"
gyp
ERR! cwd $HOME/airlab/repos/DefinitelyTyped/node_modules/nodegit
gyp ERR! node -v v10.10.0
gyp
ERR! node-gyp -v v3.8.0
gyp ERR! not ok
[nodegit] ERROR - Could not finish install
[nodegit] ERROR - finished with error code: 1 |
|
@ljharb That may be nodegit/nodegit#1490. You should be able to just ignore this and run |
npm test.)npm run lint package-name(ortscif notslint.jsonis present).If changing an existing definition:
new Buffer('').constructor === Buffer, in every node version evertslint.jsoncontaining{ "extends": "dtslint/dt.json" }.