Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type definitions file #212

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ jobs:
- run: yarn lint:eslint
- run: yarn lint:prettier --no-write --check

test-types:
name: Test Types
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4
with:
node-version: lts/*
- run: corepack enable
- run: yarn install
- run: yarn test:types --target 4.8,5.0,latest

test-node:
name: Test on Node.js v${{ matrix.node-version }}
strategy:
Expand Down
24 changes: 24 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export interface Options {
/**
* The {@link https://docusaurus.io/docs/markdown-features/tabs#syncing-tab-choices | `groupId`}
* property for all instances of `Tabs` component created by this plugin.
*/
groupId?: string;
/**
* List with tuples with code block language attribute and tab label text.
*/
labels?: Array<[string, string]>;
/**
* Whether tab choices should be {@link https://docusaurus.io/docs/markdown-features/tabs#syncing-tab-choices | synced}
* between all tabs created by this plugin.
*/
sync?: boolean;
}

/**
* Turns Docusaurus {@link https://docusaurus.io/docs/next/markdown-features/code-blocks | code blocks}
* into {@link https://docusaurus.io/docs/next/markdown-features/tabs | tabs}.
*/
declare function tabBlocks(options?: Options): void;

export default tabBlocks;
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
},
"license": "MIT",
"type": "module",
"main": "index.js",
"exports": {
".": "./index.js"
},
"files": [
"index.js"
],
"scripts": {
"lint": "yarn lint:eslint && yarn lint:prettier",
"lint:eslint": "eslint . --ext js",
"lint:prettier": "prettier . --no-config --write",
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
"test:types": "tstyche"
},
"dependencies": {
"unist-util-is": "^6.0.0",
Expand All @@ -41,7 +44,9 @@
"jest": "29.7.0",
"prettier": "3.0.3",
"remark": "15.0.1",
"remark-mdx": "3.0.0"
"remark-mdx": "3.0.0",
"tstyche": "1.0.0-beta.3",
"typescript": "5.2.2"
},
"packageManager": "yarn@4.0.1",
"engines": {
Expand Down
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",

// "allowJs": true,
// "checkJs": true,

"noEmit": true,

"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,

"strict": true,
"allowUnreachableCode": false,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,

"skipLibCheck": true
}
}
20 changes: 20 additions & 0 deletions typetests/index.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, test } from "tstyche";
import tabBlocks, { type Options } from "docusaurus-remark-plugin-tab-blocks";

const options: Options = {};

test("tabBlocks()", () => {
expect(tabBlocks()).type.toBeVoid();
expect(tabBlocks(options)).type.toBeVoid();
});

test("Options", () => {
expect(options).type.toBeAssignable({ groupId: "code-examples" });
expect(options).type.toBeAssignable({
labels: [
["js", "JavaScript"] as [string, string],
["ts", "TypeScript"] as [string, string],
],
});
expect(options).type.toBeAssignable({ sync: true });
});
36 changes: 36 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,8 @@ __metadata:
prettier: "npm:3.0.3"
remark: "npm:15.0.1"
remark-mdx: "npm:3.0.0"
tstyche: "npm:1.0.0-beta.3"
typescript: "npm:5.2.2"
unist-util-is: "npm:^6.0.0"
unist-util-visit: "npm:^5.0.0"
languageName: unknown
Expand Down Expand Up @@ -4812,6 +4814,20 @@ __metadata:
languageName: node
linkType: hard

"tstyche@npm:1.0.0-beta.3":
version: 1.0.0-beta.3
resolution: "tstyche@npm:1.0.0-beta.3"
peerDependencies:
typescript: 4.x || 5.x
peerDependenciesMeta:
typescript:
optional: true
bin:
tstyche: build/bin.js
checksum: 8db6acde30b8905c891c3854837340e7bbfee20e79e6eae2e674e1e966737f8c79079325c330b51b922f3157a3fcb26da0005032a45ade302f20b1d3e3ccfd37
languageName: node
linkType: hard

"tsutils@npm:^3.21.0":
version: 3.21.0
resolution: "tsutils@npm:3.21.0"
Expand Down Expand Up @@ -4853,6 +4869,26 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:5.2.2":
version: 5.2.2
resolution: "typescript@npm:5.2.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 91ae3e6193d0ddb8656d4c418a033f0f75dec5e077ebbc2bd6d76439b93f35683936ee1bdc0e9cf94ec76863aa49f27159b5788219b50e1cd0cd6d110aa34b07
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A5.2.2#optional!builtin<compat/typescript>":
version: 5.2.2
resolution: "typescript@patch:typescript@npm%3A5.2.2#optional!builtin<compat/typescript>::version=5.2.2&hash=f3b441"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 062c1cee1990e6b9419ce8a55162b8dc917eb87f807e4de0327dbc1c2fa4e5f61bc0dd4e034d38ff541d1ed0479b53bcee8e4de3a4075c51a1724eb6216cb6f5
languageName: node
linkType: hard

"undici-types@npm:~5.26.4":
version: 5.26.5
resolution: "undici-types@npm:5.26.5"
Expand Down