Skip to content

Commit fd79393

Browse files
authored
fix: fixed up ts error on /website (#230)
* fix: fixed up ts error on `/website` * feat(deps): 增加@types react|react-dom to ^18.2.0 version
1 parent 15a1fe2 commit fd79393

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"@kkt/raw-modules": "~7.1.1",
5353
"@kkt/scope-plugin-options": "~7.1.1",
5454
"@types/babel__standalone": "~7.1.4",
55-
"@types/react": "~18.0.5",
56-
"@types/react-dom": "~18.0.1",
55+
"@types/react": "^18.2.69",
56+
"@types/react-dom": "^18.2.22",
5757
"@types/react-test-renderer": "~18.0.0",
5858
"@uiw/react-github-corners": "~1.5.14",
5959
"@uiw/react-markdown-preview": "~4.0.6",
@@ -102,4 +102,4 @@
102102
"last 1 safari version"
103103
]
104104
}
105-
}
105+
}

typing.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* 增加这个文件是为了解决全局的ts 对 `md|less`后缀的文件引用后ts的报错问题
3+
* @see bugs(https://github.com/uiwjs/react-code-preview/issues/229)
4+
*/
5+
declare module '*.md';
6+
declare module '*.less';

website/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import '@wcj/dark-mode';
55
import DocumentStr from '../README.md';
66
import styles from './App.module.less';
77
import Example from './Example';
8+
import pkgJson from '../package.json';
89

910
export default function App() {
10-
// @ts-ignore
11-
const version = VERSION;
11+
const version = pkgJson.version;
1212
let DocumentStrSource = DocumentStr;
1313
if (DocumentStrSource) DocumentStrSource = DocumentStr.replace(/([\s\S]*)<!--dividing-->/, '');
1414
return (

website/Example.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, useState, useEffect } from 'react';
1+
import React, { Fragment, useState, useEffect } from 'react';
22
import CodePreview from '../';
33
import { Switch } from 'uiw';
44
import * as UIW from 'uiw';

website/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import ReactDOM from 'react-dom/client';
44
import '@uiw/reset.css/reset.less';
55
import App from './App';
66

7-
ReactDOM.createRoot(document.getElementById('root')).render(
7+
/**
8+
* 增加一个❕,解决ts报错的问题
9+
* 因为 `document.getElementById('root')`有可能为null
10+
* @see https://github.com/uiwjs/react-code-preview/issues/229
11+
*/
12+
ReactDOM.createRoot(document.getElementById('root')!).render(
813
<React.StrictMode>
914
<App />
1015
</React.StrictMode>,

0 commit comments

Comments
 (0)