From 1a8ce87f28b1571918ea6da33a04fcd193933d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 29 Mar 2021 15:46:46 +0200 Subject: [PATCH] Fix types and make sure Typescript types validate --- .circleci/config.yml | 3 +++ lib/index.d.ts | 9 +++++---- package-lock.json | 6 ++++++ package.json | 4 +++- tsconfig.json | 1 + 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 tsconfig.json diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b24243..801ba16 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,6 +44,9 @@ jobs: - run: name: Run Linting command: npm run lint + - run: + name: Check types + command: npm run check-types - run: name: Run Security Check command: npm run security diff --git a/lib/index.d.ts b/lib/index.d.ts index 686ff6d..e21cbe5 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -10,6 +10,7 @@ */ import * as postcss from "postcss"; +import * as postcssNode from "postcss/lib/node"; // Even though the concrete classes extend PostCSS classes, we can't extend // PostCSS Node types here because they refer to statements that aren't @@ -26,12 +27,12 @@ export interface NodeBase { replaceWith(...nodes: Array): this; // Inherited from postcss.ContainerBase with no changes. - source?: postcss.NodeSource; - raws: postcss.NodeRaws; + source?: postcss.Source; + raws: any; toString(stringifier?: Stringifier | Syntax): string; error( message: string, - options?: postcss.NodeErrorOptions + options?: postcssNode.NodeErrorOptions ): postcss.CssSyntaxError; warn( result: postcss.Result, @@ -131,7 +132,7 @@ export type ChildNode = export type Container = Root | Func | Interpolation; -export interface AtWord extends NodeBase { +export interface AtWord extends ContainerBase { type: "atrule"; parent: Container; name: string; diff --git a/package-lock.json b/package-lock.json index d2e4d30..6f8d2f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5401,6 +5401,12 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", + "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", + "dev": true + }, "unique-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-2.0.0.tgz", diff --git a/package.json b/package.json index da7744e..c337892 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "ci:coverage": "nyc npm run test && nyc report --reporter=text-lcov > coverage.lcov", "ci:test": "npm run test", "lint": "eslint lib test --fix --cache", + "check-types": "tsc --noEmit", "lint-staged": "lint-staged", "security": "npm audit --audit-level=moderate", "test": "ava" @@ -48,7 +49,8 @@ "prettier": "^2.1.2", "rewiremock": "^3.14.3", "strip-ansi": "^6.0.0", - "text-table": "^0.2.0" + "text-table": "^0.2.0", + "typescript": "^4.2.3" }, "peerDependencies": { "postcss": "^8.0.9" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1 @@ +{}