Skip to content

Commit

Permalink
Add libdefs for dotenv v8 (#3664)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienw authored and AndrewSouthpaw committed Dec 11, 2019
1 parent 1b510de commit 9899c09
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
23 changes: 23 additions & 0 deletions definitions/npm/dotenv_v8.x.x/flow_v0.53.x-/dotenv_v8.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @flow

declare module 'dotenv' {
declare type ParseResult = {| [key: string]: string |};
declare type ConfigResult = {| parsed: ParseResult |} | {| error: Error |};
declare function config(
options?: $Shape<{| path: string, encoding: string, debug: boolean |}>
): ConfigResult;

declare function parse(
buffer: Buffer | string,
options?: $Shape<{| debug: boolean |}>
): ParseResult;

declare module.exports: {|
config: typeof config,
parse: typeof parse,
|};
}

// eslint-disable-next-line no-empty
declare module 'dotenv/config' {
}
58 changes: 58 additions & 0 deletions definitions/npm/dotenv_v8.x.x/test_dotenv_v8.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// @flow

import dotenv from 'dotenv';
import 'dotenv/config';

const configResult = dotenv.config();
if (configResult.error) {
(configResult.error: Error);

// $ExpectError
(parsed['KEY']: string);
} else {
const parsed = configResult.parsed;
(parsed['KEY']: string);

// $ExpectError
(parsed['KEY']: number);

// $ExpectError
(parsed[1]: string);
}

dotenv.config({
encoding: 'utf8'
});

dotenv.config({
path: '.env'
});

dotenv.config({
encoding: 'utf8',
path: '.env',
debug: true,
});

// $ExpectError
dotenv.config({ foo: 'bar' });

const parsed = dotenv.parse('KEY=VALUE');
(parsed['KEY']: string);

// $ExpectError
(parsed['KEY']: number);

// $ExpectError
(parsed[1]: string);

dotenv.parse('KEY=VALUE', { debug: true });

// $ExpectError
dotenv.parse('KEY=VALUE', { debug: 'foo' });

// $ExpectError
dotenv.parse('KEY=VALUE', { foo: 'bar' });

// $ExpectError
dotenv.foo();

0 comments on commit 9899c09

Please sign in to comment.