Skip to content
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

Typings: add generic support to parse function #530

Closed
ericmorand opened this issue May 12, 2021 · 1 comment
Closed

Typings: add generic support to parse function #530

ericmorand opened this issue May 12, 2021 · 1 comment

Comments

@ericmorand
Copy link
Contributor

Currently, parse is declared as returning DotenvParseOutput. This forces people wanting to have typed environmental configuration to typehint the result of parse as any:

type Configuration = {
    FOO: string
};

const configuration: Configuration = parse(readFileSync('.env')) as any;

This looks not very elegant and could be solved easily by having parse function being generic:

type Configuration = {
    FOO: string
};

const configuration= parse<Configuration>(readFileSync('.env'));
ericmorand pushed a commit to ericmorand/dotenv that referenced this issue May 12, 2021
ericmorand added a commit to ericmorand/dotenv that referenced this issue May 12, 2021
motdotla added a commit that referenced this issue May 19, 2021
Issue #530 - Typings: add generic support to parse function
@motdotla
Copy link
Owner

Thanks again for this @ericmorand. Going out as part of 10.0.0

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

2 participants