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

[Bug]: The document's sample code is of incorrect type #1818

Closed
markH5 opened this issue Feb 6, 2025 · 2 comments · Fixed by #1837
Closed

[Bug]: The document's sample code is of incorrect type #1818

markH5 opened this issue Feb 6, 2025 · 2 comments · Fixed by #1837

Comments

@markH5
Copy link

markH5 commented Feb 6, 2025

Version

System:win10 x64
Browsers:
npmPackages:pnpm 10.2.0

Details

https://rspress.dev/guide/advanced/custom-theme#3-custom-home-page-and-404-page
https://rspress.dev/zh/guide/advanced/custom-theme#3-%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6

has some type error

Reproduce link

https://github.com/markH5/my_search_doc_err

Reproduce Steps

Setup 1

Install the dependencies:

pnpm create rspress@latest
pnpm i react
pnpm i react-dom

pnpm i typescript -D
pnpm i @types/react -D
pnpm i @types/react-dom -D

get

  "dependencies": {
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "rspress": "^1.40.2"
  },
  "devDependencies": {
    "@types/node": "^18.11.17",
    "@types/react": "^19.0.8",
    "@types/react-dom": "^19.0.3",
    "typescript": "^5.7.3"
  }

Setup 2

copy code from doc https://rspress.dev/guide/advanced/custom-theme#3-custom-home-page-and-404-page

// theme/index.tsx
import Theme, { Search } from 'rspress/theme';

// Use slot
const Layout = () => <Theme.Layout beforeNavTitle={<div>some content</div>} />;
// Custom Home Page
const HomeLayout = () => <div>Home</div>;
// Custom 404 page
const NotFoundLayout = () => <div>404</div>;

export default {
  ...Theme,
  Layout,
  HomeLayout,
  NotFoundLayout,
};

// Custom Search Component
const MySearch = () => <div className="my-search">{Search}</div>;
export { MySearch as Search };
// re-export
export * from 'rspress/theme';

type error

hover at {Search} get ts type error

Type '() => Element' is not assignable to type 'ReactNode'. ts(2322)
markH5 added a commit to markH5/my_search_doc_err that referenced this issue Feb 6, 2025
@SoonIter
Copy link
Member

SoonIter commented Feb 7, 2025

- const MySearch = () => <div className="my-search">{Search}</div>;
+ const MySearch = () => <div className="my-search"><Search /></div>;

try this line, might be doc mistake

@markH5
Copy link
Author

markH5 commented Feb 10, 2025

I guess so, it can work now, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants