prettier-package-json: Add type definitions (#35790)

This commit is contained in:
Daniel Cassidy 2019-05-28 21:49:57 +01:00 committed by Sheetal Nandi
parent 8ce8f37634
commit 5ce88a3373
4 changed files with 111 additions and 0 deletions

18
types/prettier-package-json/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
// Type definitions for prettier-package-json 2.1
// Project: https://github.com/cameronhunter/prettier-package-json
// Definitions by: Daniel Cassidy <https://github.com/djcsdy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export type CompareFn = (a: string, b: string) => number;
export interface Options {
tabWidth?: number;
useTabs?: boolean;
expandUsers?: boolean;
keyOrder?: ReadonlyArray<string> | CompareFn;
}
export function format(json: object, options?: Options): string;
export function check(json: string | object, options?: Options): boolean;

View File

@ -0,0 +1,69 @@
import { format, check } from "prettier-package-json";
const json = {
name: "some-package",
version: "0.0.0"
};
// $ExpectType string
format(json);
// $ExpectType string
format(json, {});
// $ExpectType string
format(json, {
tabWidth: 2,
useTabs: false,
expandUsers: false,
keyOrder: ["name", "version"]
});
// $ExpectType string
format(json, {
tabWidth: 4,
useTabs: true,
expandUsers: true,
keyOrder: (a, b) => {
// $ExpectType string
a;
// ExpectType string
b;
return b < a ? -1 : b > a ? 1 : 0;
}
});
// $ExpectType boolean
check("");
// $ExpectType boolean
check(json);
// $ExpectType boolean
check("", {});
// $ExpectType boolean
check(json, {});
// $ExpectType boolean
check("", {
tabWidth: 8,
useTabs: true,
expandUsers: false,
keyOrder: ["private", "version"]
});
// $ExpectType boolean
check(json, {
keyOrder: (a, b) => {
// $ExpectType string
a;
// $ExpectType string
b;
return b < a ? -1 : b > a ? 1 : 0;
}
});

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"prettier-package-json-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }