-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
node: process.stdin is a stream.Readable and process.stdout is a stream.Writable #20493
Conversation
types/hexo-fs/index.d.ts to author (@segayuu). Could you review this PR? types/node/index.d.ts to authors (@DefinitelyTyped/DefinitelyTyped @parambirs @tellnes @WilcoBakker @octo-sniffle @smac89 @Flarna @mwiktorczyk @wwwy3y3 @Tyriar @DeividasBakanas @kjin @alvis Microsoft TypeScript (account can't be detected)). Could you review this PR? |
@dex4er Please fix the failures indicated in the Travis CI log. |
types/node/index.d.ts
Outdated
@@ -5033,7 +5084,7 @@ declare module "stream" { | |||
isPaused(): boolean; | |||
unpipe<T extends NodeJS.WritableStream>(destination?: T): this; | |||
unshift(chunk: any): void; | |||
wrap(oldStream: NodeJS.ReadableStream): Readable; | |||
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be not correct. warp method returns a Readable
class or even better this
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so maybe better is wrap<T extends NodeJS.ReadableStream>(oldStream: NodeJS.ReadableStream): T
It will break some modules which define wrap
method, but it is very easy to fix (maybe 3 modules in DefinitelyTyped repo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be wrap(oldStream: NodeJS.ReadableStream): this
as this is how it is implemented (and documented).
types/node/index.d.ts
Outdated
openStdin(): Socket; | ||
stdout: StdWriteStream; | ||
stderr: StdWriteStream; | ||
stdin: StdReadStream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The StdReadStream
you defined has a setRawMode()
and isRaw
like tty.ReadStream
.
If you pipe in a file to node process.stdin
doesn't have them.
I wonder why there are new types added as NodeJs docu tells that |
@Flarna It would be better to use stdin: fs.ReadStream | tty.Socket; but stdin: NodeJS.ReadStream | NodeJS.Socket; but... it is very inconvenient. It would mean that I had to check the console.log(process.stdin.isTTY); // fails because not defined in fs.ReadStream
console.log(process.stdin.path); // fails because not defined in net.Socket So that was idea behind console.log(process.stdin.isTTY); // undefined when stdin is fs.ReadStream
console.log(process.stdin.path); // undefined when stdin is net.Socket |
With your proposed solution it's valid to write |
@Flarna Contre-proposition is to really make if (process.stdin.isTTY) console('this is tty'); and you should replace it with: if (process.stdin instanceof tty.ReadStream) console('this is tty'); Maybe this is the right way in Typescript and we should not take all patterns from Javascript blindly. |
I did a closer look into the various definition of streams. Hopefully I understand your problem and proposal better now. One issue is that it seems we can't use the "correct" types Maybe an alternative to keep interfaces in NodeJS and classes in stream/... in sync would be to define the classes already in NodeJS and re-export the type and constructor in stream/... But I'm not sure which side effects this may have. |
@Flarna ok so this is another try, after rebase to the newest master:
Now most of problems are fixed and changed don't break other modules, except |
Thanks! Hope this still solves the problems you have seen. |
@Flarna I'm sorry to say I never used the stream and blob APIs. Actually, I just followed the reference document of node-firebird( https://github.com/xdenser/node-firebird-libfbclient#stream-object) about them. It's author @xdenser could help about the relation between Firebird Streams and NodeJS Streams. APPEND: |
@karak @Flarna I made the changes for
|
types/hexo-fs/index.d.ts
Outdated
@@ -426,11 +426,6 @@ export function writeFile( | |||
*/ | |||
export function writeFileSync(path: string, data: any, options?: string | { encoding?: string | null; mode?: string | number; flag?: string }): void; | |||
|
|||
// Static classes | |||
export let Stats: Stats; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to remove an exported variable from an unrelated module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can reexport class from fs
to get the same behaviour as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now rebased and fixed
…; change interfaces in fs, dgram and net into classes
…tream interface (and Write...)
Thanks! |
…am.Writable (DefinitelyTyped#20493) * Readable.wrap returns this * Add missing properties to interface ReadableStream and WritableStream; change interfaces in fs, dgram and net into classes * Move all additional properties from ReadableStream interface to ReadStream interface (and Write...) * hexo-fs should re-export classes from 'fs' * process.stdin._destroy is a function
New interfaces
NodeJS.Readable
andNodeJS.Writable
have the same propertiesas in
stream.Readable
andstream.Writable
classes.Interface
NodeJS.Socket
is just aNodeJS.ReadWriteStream
. But newinterface
NodeJS.TtyStream
(TtyWriteStream
andTtyReadStream
) hasextra properties as in
tty.ReadStream
andtty.WriteStream
.process.stdin
implementsNodeJS.TtyReadStream
andprocess.stdout
implementsNodeJS.TtyWriteStream
.net.Socket
,dgram.Socket
,fs.Stats
,fs.ReadStream
andfs.WriteStream
are classes.
Please fill in this template.
npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If adding a new definition:
dts-gen --dt
, not by basing it on an existing project.tslint.json
should be present, andtsconfig.json
should havenoImplicitAny
,noImplicitThis
, andstrictNullChecks
set totrue
.If changing an existing definition:
tslint.json
containing{ "extends": "dtslint/dt.json" }
.If removing a declaration:
notNeededPackages.json
.