mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat(prettier): add sync option
This commit is contained in:
parent
a7d0be726e
commit
9a49b95c1a
8
types/prettier/index.d.ts
vendored
8
types/prettier/index.d.ts
vendored
@ -102,6 +102,10 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +118,9 @@ export interface ResolveConfigOptions {
|
||||
*
|
||||
* The promise will be rejected if there was an error parsing the configuration file.
|
||||
*/
|
||||
export function resolveConfig(filePath?: string, options?: ResolveConfigOptions): Promise<null | Options>;
|
||||
export function resolveConfig(filePath: string | undefined, options: ResolveConfigOptions & { sync: true }): null | Options;
|
||||
export function resolveConfig(filePath?: string, options?: ResolveConfigOptions & { sync?: false }): Promise<null | Options>;
|
||||
export function resolveConfig(filePath?: string, options?: ResolveConfigOptions): null | Options | Promise<null | Options>;
|
||||
|
||||
/**
|
||||
* As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
|
||||
|
||||
@ -24,4 +24,30 @@ 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<Options | null> | null
|
||||
prettier.resolveConfig('path/to/somewhere', { sync: true as boolean });
|
||||
|
||||
const options = prettier.resolveConfig('path/to/somewhere', { sync: true });
|
||||
if (options !== null) {
|
||||
const formatted = prettier.format('hello world', options);
|
||||
}
|
||||
|
||||
prettier.clearConfigCache();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user