From 3445a2c1a5b3c75b440af829f69696c12b2be2b2 Mon Sep 17 00:00:00 2001 From: syy11cn Date: Fri, 29 Oct 2021 16:46:00 +0800 Subject: [PATCH] feat: add typescript support --- index.html | 2 +- package.json | 3 +++ src/{App.jsx => App.tsx} | 17 +++++++++-------- src/{main.jsx => main.tsx} | 0 src/typings/images.ts | 7 +++++++ tsconfig.json | 33 +++++++++++++++++++++++++++++++++ yarn.lock | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 89 insertions(+), 9 deletions(-) rename src/{App.jsx => App.tsx} (81%) rename src/{main.jsx => main.tsx} (100%) create mode 100644 src/typings/images.ts create mode 100644 tsconfig.json diff --git a/index.html b/index.html index b46ab83..38f3861 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,6 @@
- + diff --git a/package.json b/package.json index 2dabd44..9e25daf 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,8 @@ "react-dom": "^17.0.0" }, "devDependencies": { + "@types/react": "^17.0.33", + "@types/react-dom": "^17.0.10", "@typescript-eslint/eslint-plugin": "^5.2.0", "@typescript-eslint/parser": "^5.2.0", "@vitejs/plugin-react": "^1.0.0", @@ -43,6 +45,7 @@ "prettier": "^2.4.1", "stylelint": "^14.0.1", "stylelint-config-standard": "^23.0.0", + "typescript": "^4.4.4", "vite": "^2.6.4" } } diff --git a/src/App.jsx b/src/App.tsx similarity index 81% rename from src/App.jsx rename to src/App.tsx index 7d4eb10..c330f5b 100644 --- a/src/App.jsx +++ b/src/App.tsx @@ -1,9 +1,10 @@ -import { useState } from 'react' -import logo from './logo.svg' -import './App.css' +import * as React from 'react'; +const { useState } = React; +import logo from './logo.svg'; +import './App.css'; -function App() { - const [count, setCount] = useState(0) +const App: React.FC = () => { + const [count, setCount] = useState(0); return (
@@ -39,7 +40,7 @@ function App() {

- ) -} + ); +}; -export default App +export default App; diff --git a/src/main.jsx b/src/main.tsx similarity index 100% rename from src/main.jsx rename to src/main.tsx diff --git a/src/typings/images.ts b/src/typings/images.ts new file mode 100644 index 0000000..d0cd11e --- /dev/null +++ b/src/typings/images.ts @@ -0,0 +1,7 @@ +declare module '*.svg'; +declare module '*.png'; +declare module '*.jpg'; +declare module '*.jpeg'; +declare module '*.gif'; +declare module '*.bmp'; +declare module '*.tiff'; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..baf6163 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "lib": ["esnext", "dom"], + "baseUrl": ".", + "jsx": "react-jsx", + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + "moduleResolution": "node", + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "suppressImplicitAnyIndexErrors": true, + "noUnusedLocals": true, + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "strict": true, + "paths": { + "@/*": ["./src/*"] + }, + "noEmit": true + }, + "include": [ + "src/**/*", + "typings/**/*", + "config/**/*", + ".eslintrc.js", + ".stylelintrc.js", + ".prettierrc.js" + ], + "exclude": ["node_modules", "build", "dist"] +} diff --git a/yarn.lock b/yarn.lock index 1be75e3..63fd113 100644 --- a/yarn.lock +++ b/yarn.lock @@ -376,6 +376,32 @@ resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA== +"@types/prop-types@*": + version "15.7.4" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" + integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ== + +"@types/react-dom@^17.0.10": + version "17.0.10" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.10.tgz#d6972ec018d23cf22b99597f1289343d99ea9d9d" + integrity sha512-8oz3NAUId2z/zQdFI09IMhQPNgIbiP8Lslhv39DIDamr846/0spjZK0vnrMak0iB8EKb9QFTTIdg2Wj2zH5a3g== + dependencies: + "@types/react" "*" + +"@types/react@*", "@types/react@^17.0.33": + version "17.0.33" + resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.33.tgz#e01ae3de7613dac1094569880bb3792732203ad5" + integrity sha512-pLWntxXpDPaU+RTAuSGWGSEL2FRTNyRQOjSWDke/rxRg14ncsZvx8AKWMWZqvc1UOaJIAoObdZhAWvRaHFi5rw== + dependencies: + "@types/prop-types" "*" + "@types/scheduler" "*" + csstype "^3.0.2" + +"@types/scheduler@*": + version "0.16.2" + resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" + integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== + "@typescript-eslint/eslint-plugin@^5.2.0": version "5.2.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.2.0.tgz#2bdb247cc2e2afce7efbce09afb9a6f0a8a08434" @@ -838,6 +864,11 @@ cssesc@^3.0.0: resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee" integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg== +csstype@^3.0.2: + version "3.0.9" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.9.tgz#6410af31b26bd0520933d02cbc64fce9ce3fbf0b" + integrity sha512-rpw6JPxK6Rfg1zLOYCSwle2GFOOsnjmDYDaBwEcwoOg4qlsIVCN789VkBZDJAGi4T07gI4YSutR43t9Zz4Lzuw== + date-fns@2.x: version "2.25.0" resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.25.0.tgz#8c5c8f1d958be3809a9a03f4b742eba894fc5680" @@ -3198,6 +3229,11 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typescript@^4.4.4: + version "4.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" + integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== + unbox-primitive@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"