diff --git a/types/babel__core/babel__core-tests.ts b/types/babel__core/babel__core-tests.ts index 59414d768d..b44e45c605 100644 --- a/types/babel__core/babel__core-tests.ts +++ b/types/babel__core/babel__core-tests.ts @@ -44,6 +44,8 @@ function checkOptions(_options: babel.TransformOptions) {} function checkConfigFunction(_config: babel.ConfigFunction) {} checkOptions({ envName: 'banana' }); +// babel uses object destructuring default to provide the envName fallback so null is not allowed +// $ExpectError checkOptions({ envName: null }); checkOptions({ caller: { name: '@babel/register' } }); checkOptions({ caller: { name: 'babel-jest', supportsStaticESM: false } }); @@ -53,8 +55,6 @@ checkOptions({ caller: { name: '', tomato: true } }); checkOptions({ rootMode: 'upward-optional' }); // $ExpectError checkOptions({ rootMode: 'potato' }); -// babel uses object destructuring default to provide the envName fallback so null is not allowed -// $ExpectError // $ExpectError checkConfigFunction(() => {}); diff --git a/types/babel__core/index.d.ts b/types/babel__core/index.d.ts index 8c4f2ef25a..1315ac821b 100644 --- a/types/babel__core/index.d.ts +++ b/types/babel__core/index.d.ts @@ -592,27 +592,18 @@ export interface ConfigAPI { * * @see https://babeljs.io/docs/en/next/config-files#apicallercb */ - caller(callerCallback: (caller: TransformOptions['caller']) => T): T - /** - * While `api.version` can be useful in general, it's sometimes nice to just declare your version. - * This API exposes a simple way to do that with: - * - * @example - * api.assertVersion(7) - * - * @see https://babeljs.io/docs/en/next/config-files#apiassertversionrange - */ - assertVersion(majorVersion: number): boolean + caller(callerCallback: (caller: TransformOptions['caller']) => T): T; /** * While `api.version` can be useful in general, it's sometimes nice to just declare your version. * This API exposes a simple way to do that with: * * @example + * api.assertVersion(7) // major version only * api.assertVersion("^7.2") * * @see https://babeljs.io/docs/en/next/config-files#apiassertversionrange */ - assertVersion(semverExpression: string): boolean + assertVersion(versionRange: number | string): boolean; // NOTE: this is an undocumented reexport from "@babel/parser" but it's missing from its types // tokTypes: typeof tokTypes } @@ -636,11 +627,11 @@ export interface SimpleCacheConfigurator { /** * Permacache the computed config and never call the function again. */ - forever(): void + forever(): void; /** * Do not cache this config, and re-execute the function every time. */ - never(): void + never(): void; /** * Any time the using callback returns a value other than the one that was expected, * the overall config function will be called again and a new entry will be added to the cache. @@ -648,7 +639,7 @@ export interface SimpleCacheConfigurator { * @example * api.cache.using(() => process.env.NODE_ENV) */ - using(callback: SimpleCacheCallback): T + using(callback: SimpleCacheCallback): T; /** * Any time the using callback returns a value other than the one that was expected, * the overall config function will be called again and all entries in the cache will @@ -657,12 +648,12 @@ export interface SimpleCacheConfigurator { * @example * api.cache.invalidate(() => process.env.NODE_ENV) */ - invalidate(callback: SimpleCacheCallback): T + invalidate(callback: SimpleCacheCallback): T; } // https://github.com/babel/babel/blob/v7.3.3/packages/babel-core/src/config/caching.js#L231 -export type SimpleCacheKey = string | boolean | number | null | undefined -export type SimpleCacheCallback = () => T +export type SimpleCacheKey = string | boolean | number | null | undefined; +export type SimpleCacheCallback = () => T; /** * Since `NODE_ENV` is a fairly common way to toggle behavior, Babel also includes an API function @@ -675,18 +666,14 @@ export interface EnvFunction { /** * @returns the current `envName` string */ - (): string - /** - * @returns `true` if the `envName` is `===` the argument - */ - (envName: string): boolean + (): string; /** * @returns `true` if the `envName` is `===` any of the given strings */ - (envNames: ReadonlyArray): boolean + (envName: string | ReadonlyArray): boolean; // the official documentation is completely wrong for this one... // this just passes the callback to `cache.using` but with an additional argument. - (envCallback: (envName: NonNullable) => T): T + (envCallback: (envName: NonNullable) => T): T; } export type ConfigFunction = (api: ConfigAPI) => TransformOptions;