-
Notifications
You must be signed in to change notification settings - Fork 10
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
process.stdout should be WritableStream | tty.WriteStream #19
Comments
Seems like a good change. I think both the read and write streams should just be updated to the |
They are totally different classes though. tty streams inherit from net.Socket |
Ok, then what I should have said is to create new interfaces for this. I don't think you'd want a union here, TypeScript would still complain it doesn't exist until you do a type assertion then. Edit: Sorry, you're right. Read the example wrong. You're definitely welcome to do a PR to quickly update as well 😄 |
Ok, so it turns out this is a real PITA to fix - any ideas? The issue is that the |
@blakeembrey shouldn't this work? import {Process} from 'process';
declare const process: Process; Assuming |
No. You can't do that because the second you put |
And the other way around? declare namespace NodeJS {
export interface Process {}
}
declare module 'process' {
type Process = NodeJS.Process;
export {Process};
} |
Yes, that's possible - but it requires moving all of |
And you cannot use |
Correct 👍 But this isn't just in the namespace, My initial thought is a TypeScript directive that'll ensure the file is always considered global or external. /cc @mhegazy @RyanCavanaugh How feasible would it be to allow |
@blakeembrey It could be a new triple-slash directive. Alternatively, it would also be enough if we could declare const process: NodeJS.Process;
declare namespace NodeJS {
export {Process} from 'process';
} |
I don't understand the question -- TypeScript always considers files as global or module depending on presence of top-level |
So we would change the whole declaration file to a module, but then put the majority of it inside |
@blakeembrey Could we even make individual files for the core node modules that are purely external? And then have one index that imports everything and declares the globals? |
@RyanCavanaugh And that's exactly our problem. We need to share an interface globally |
@felixfbecker Unfortunately that's not possible either, because we need to put Using |
@RyanCavanaugh I just tried out your suggestion, but it doesn't work: declare module 'process' {
export interface Process {}
}
import {Process} from 'process';
declare global {
const process: Process; // Error: Module augmentation cannot introduce new names in the top level scope.
} |
@felixfbecker I think the other issue with that is that |
That error can be circumvented by doing: process.d.ts export interface Process {} node.d.ts import {Process} from './process';
declare global {
const process: Process; // Error: Module augmentation cannot introduce new names in the top level scope.
} The error I mentioned remains though. |
@felixfbecker Correct, but then there's no |
The only way around all this may be to combine module files, references and imports. E.g. Write Edit: However, none of this fixes the concerns mentioned in #19 (comment) because having |
@blakeembrey Besides the error that is fixed in TS2.0, I found a solution: process.d.ts declare module 'process' {
export interface Process {}
} node.d.ts /// <reference path="./process.d.ts" />
import {Process} from 'process';
declare global {
declare const process: Process;
} |
Yes, that's the proposal I suggested above. But it does not fix the concern I expressed (also above). |
From https://nodejs.org/api/tty.html#tty_tty:
It's currently not possible to check
process.stdout.isTTY
because it is only typed asWritableStream
. It should beWritableStream | tty.WriteStream
.The alternative check
process.stdout instanceof tty.WriteStream
is not possible either, becausetty
only exports interfaces, not the classes / constructors.The same applies to
process.stdin
/tty.ReadStream
The text was updated successfully, but these errors were encountered: