Skip to content

Commit

Permalink
👷 Add TypeScript checks on website (#4155)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz authored Aug 26, 2023
1 parent 6fdeb82 commit 2cbebb5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
import React, { useState } from 'react';
import {
SandpackProvider,
Expand All @@ -13,7 +12,14 @@ import { atomDark } from '@codesandbox/sandpack-themes';
import styles from './Playgrounds.module.css';
import * as snippets from './snippets.mjs';

function SetupPlayground(props) {
type Props = {
startSpecCode: string;
anwserSpecCode: string;
fileContent: string;
fileName: string;
fileExtension: string;
};
function SetupPlayground(props: Props) {
const { startSpecCode, anwserSpecCode, fileContent, fileName, fileExtension } = props;
const [specFile, setSpecFile] = useState({ key: 0, content: startSpecCode });

Expand Down Expand Up @@ -116,13 +122,13 @@ export function MissingPart() {
);
}

function codeWithComments(code, comments) {
function codeWithComments(code: string, comments: string[]): string {
return `${comments.map((line) => `// ${line}`).join('\n')}\n\n${code}`;
}
function pastImplementationSnippet(code, partName) {
function pastImplementationSnippet(code: string, partName: string): string {
return codeWithComments(code, ['Implementation used within the part:', '> ' + partName]);
}
function pastTestSnippet(code, partName, variationName) {
function pastTestSnippet(code: string, partName: string, variationName?: string | undefined): string {
return codeWithComments(code, [
'Test suggested for the part:',
'> ' + partName,
Expand Down
1 change: 1 addition & 0 deletions website/docs/tutorials/detect-race-conditions/snippets.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
// Does not queue at all
export const queueCodeV0 = `export function queue(fun) {
return fun;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
import { jest } from '@jest/globals';
import { jest, beforeAll, afterAll, describe, it, expect } from '@jest/globals';
import * as path from 'path';
import * as url from 'url';
import { promises as fs } from 'fs';
Expand Down
8 changes: 5 additions & 3 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@codesandbox/sandpack-react": "^2.6.9",
"@codesandbox/sandpack-themes": "^2.0.21",
"@docusaurus/core": "2.4.1",
"@docusaurus/preset-classic": "2.4.1",
"@docusaurus/remark-plugin-npm2yarn": "2.4.1",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^18.2.0",
Expand All @@ -28,8 +28,10 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "2.4.1",
"@jest/globals": "^29.6.2",
"@tsconfig/docusaurus": "^2.0.0",
"fast-check": "workspace:*",
"jest": "^29.6.4"
"jest": "^29.6.4",
"typescript": "~5.1.6"
},
"browserslist": {
"production": [
Expand Down
7 changes: 7 additions & 0 deletions website/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@tsconfig/docusaurus/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"types": ["node", "@docusaurus/module-type-aliases", "@docusaurus/theme-classic"]
}
}
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3946,6 +3946,13 @@ __metadata:
languageName: node
linkType: hard

"@tsconfig/docusaurus@npm:^2.0.0":
version: 2.0.0
resolution: "@tsconfig/docusaurus@npm:2.0.0"
checksum: 39adca336d9d8d6838c982212e6661c3d211d02244be17861cae4e16b9b5ee9aa0f2d48099649417794b0c2b7661e53905615f94ffb4b5608a326f5b55194e2f
languageName: node
linkType: hard

"@tufjs/canonical-json@npm:1.0.0":
version: 1.0.0
resolution: "@tufjs/canonical-json@npm:1.0.0"
Expand Down Expand Up @@ -16882,13 +16889,14 @@ __metadata:
"@docusaurus/preset-classic": 2.4.1
"@docusaurus/remark-plugin-npm2yarn": 2.4.1
"@jest/globals": ^29.6.2
"@mdx-js/react": ^1.6.22
"@tsconfig/docusaurus": ^2.0.0
clsx: ^1.2.1
fast-check: "workspace:*"
jest: ^29.6.4
prism-react-renderer: ^1.3.5
react: ^18.2.0
react-dom: ^18.2.0
typescript: ~5.1.6
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 2cbebb5

Please sign in to comment.