From 1c7070ef2ea0552a868fab0ac4aa73236bd87c11 Mon Sep 17 00:00:00 2001 From: ikatyang Date: Fri, 1 Sep 2017 13:47:54 +0800 Subject: [PATCH] feat(prettier): replace `sync` option with `.sync()` method --- types/prettier/index.d.ts | 11 ++++------- types/prettier/prettier-tests.ts | 23 +---------------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/types/prettier/index.d.ts b/types/prettier/index.d.ts index 07cf09fbba..317a514912 100644 --- a/types/prettier/index.d.ts +++ b/types/prettier/index.d.ts @@ -102,10 +102,6 @@ export interface ResolveConfigOptions { * If set to `false`, all caching will be bypassed. */ useCache?: boolean; - /** - * If set to `true`, result will be returned directly. - */ - sync?: boolean; } /** @@ -118,9 +114,10 @@ export interface ResolveConfigOptions { * * The promise will be rejected if there was an error parsing the configuration file. */ -export function resolveConfig(filePath: string | undefined, options: ResolveConfigOptions & { sync: true }): null | Options; -export function resolveConfig(filePath?: string, options?: ResolveConfigOptions & { sync?: false }): Promise; -export function resolveConfig(filePath?: string, options?: ResolveConfigOptions): null | Options | Promise; +export function resolveConfig(filePath?: string, options?: ResolveConfigOptions): Promise; +export namespace resolveConfig { + function sync(filePath?: string, options?: ResolveConfigOptions): null | Options; +} /** * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache. diff --git a/types/prettier/prettier-tests.ts b/types/prettier/prettier-tests.ts index e88ebe4770..8d95196101 100644 --- a/types/prettier/prettier-tests.ts +++ b/types/prettier/prettier-tests.ts @@ -24,28 +24,7 @@ prettier.resolveConfig('path/to/somewhere').then(options => { } }); -prettier.resolveConfig('path/to/somewhere', undefined).then(options => { - if (options !== null) { - const formatted = prettier.format('hello world', options); - } -}); - -prettier.resolveConfig('path/to/somewhere', {}).then(options => { - if (options !== null) { - const formatted = prettier.format('hello world', options); - } -}); - -prettier.resolveConfig('path/to/somewhere', { sync: false }).then(options => { - if (options !== null) { - const formatted = prettier.format('hello world', options); - } -}); - -// $ExpectType Options | Promise | null -prettier.resolveConfig('path/to/somewhere', { sync: true as boolean }); - -const options = prettier.resolveConfig('path/to/somewhere', { sync: true }); +const options = prettier.resolveConfig.sync('path/to/somewhere'); if (options !== null) { const formatted = prettier.format('hello world', options); }