Usage in a preact/compat codebase with TypeScript
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- next.js, react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Tái hiện lỗi trong dự án Next.js được mô tả bằng cách sử dụng preact/compat và tsconfig được cung cấp. Kiểm tra bề mặt TypeScript của preact-markup cùng với định nghĩa JSX ElementClass của @types/react; được coi là hoàn tất khi Markup có thể được sử dụng trong JSX mà không gặp lỗi kiểu được báo cáo và vẫn giữ được khả năng hoàn tất trong trình soạn thảo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This might not be directly an issue, but I'm looking for some advice.
I'm trying to use this package (preact-markup@2.1.1) in a Next.js codebase set up with preact/compat as detailed in the using-preact example. I've also got TypeScript configured, with the following tsconfig:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext", "ESNext.Intl", "ES2018.Intl"],
"allowJs": false,
"skipLibCheck": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"typeRoots": ["node_modules/@types", "./src/types"]
},
"exclude": ["node_modules", ".next", "out"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"]
}
I haven't followed the advice to add "jsxImportSource": "preact", from the Preact TS docs as that causes hundreds of errors in our codebase. I'm guessing that would be beneficial in a 'pure' Preact codebase, but isn't useful here. (If you can confirm this hunch, that would be great).
Now, the issue here is that, when I try to use <Markup /> in my JSX, I'm getting the following TS error:
'Markup' cannot be used as a JSX component.
Its instance type 'Markup' is not a valid JSX element.
Property 'refs' is missing in type 'Markup' but required in type 'ElementClass'.ts(2786)
ElementClass is defined in @types/react, likely because the TS compiler (erroneously) figures that (the return value of) any component used in JSX should extend JSX.ElementClass. I'm by no means a very experienced TS user, so this is a best guess.
Now, I've tried to monkey patch the type of Markup like this by overwriting the keys the TS compiler complains about in my own code:
import BaseMarkup from 'preact-markup';
import { ReactInstance } from 'react';
const Markup = BaseMarkup as typeof BaseMarkup & {
refs: { [key: string]: ReactInstance };
};
export { Markup };
Unfortunately, that doesn't work either as it doesn't seem to be possible to extend classes like this. Now I could probably just go const Markup = BaseMarkup as any; and call it a day, but I would like to find a way to accurately type this for my codebase, if at all possible so we can keep code completion in our editors. Is it possible to get this typed correctly somehow?
- Ngôn ngữ chính
- JavaScript
- Star
- 207
- Fork
- 27
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của developit/preact-markup
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 35/100
developit/preact-markup#50 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
developit/preact-markup#49 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
developit/preact-markup#25 · 2 bình luận ·
-
Default to HTML parsing? Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
developit/preact-markup#11 · 5 bình luận ·
-
question
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
developit/preact-markup#10 · 1 bình luận · 1 reaction ·
Tất cả issue của developit/preact-markup
Issue tương tự
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Improve Title Support Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·