Skip to content

Type of process.env should be { [key: string]: string } #11615

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

Closed
ThibaultRiviere opened this issue Sep 29, 2016 · 4 comments
Closed

Type of process.env should be { [key: string]: string } #11615

ThibaultRiviere opened this issue Sep 29, 2016 · 4 comments

Comments

@ThibaultRiviere
Copy link

This will allow to typescript to trigger compile error :

    const x: number = process.env.x;

See microsoft/TypeScript/issues/11239

@ThibaultRiviere ThibaultRiviere changed the title Type of process.env should be { [key: string]: string } Type of process.env should be { [key: string]: string } Sep 29, 2016
@mizunashi-mana
Copy link

I see what you mean. However, this request have a problem.

const val: { [key: string]: string; } = { 'x': 'str', };
const x = val.x;

This code reports error: error TS2339: Property 'x' does not exist on type '{ [key: string]: string; }'.
If process.env had type { [key: string]: string; }, your code would be:

const x: number = process.env['x']; // type error!

There is a problem from compatibility, and it may be different from what you mean.

Actually, I recommend this request. But, because many typescript users use syntax on their program such as process.env.x, for compatibility, we might be better to use any type for process.env.

@mizunashi-mana
Copy link

May be related to microsoft/TypeScript#560

This definition partially solves this problem.
https://github.com/types/env-node/blob/master/6/node.d.ts#L460-L463

Such code is correct on env~node:

const path = process.env.PATH;

However, this code is invalid:

const x = process.env.x

@vvakame
Copy link
Member

vvakame commented Sep 30, 2016

please send a pull request. I'll review it.

tomc974 added a commit to tomc974/DefinitelyTyped that referenced this issue Jun 23, 2017
tomc974 added a commit to tomc974/DefinitelyTyped that referenced this issue Jun 23, 2017
tomc974 added a commit to tomc974/DefinitelyTyped that referenced this issue Jun 23, 2017
tomc974 added a commit to tomc974/DefinitelyTyped that referenced this issue Jun 23, 2017
@orta orta closed this as completed Jun 7, 2021
@orta
Copy link
Collaborator

orta commented Jun 7, 2021

Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants