Я создал этот файл, чтобы проверить поведение, которое мне нужно: < /p>
import { z } from "zod";
// SCHEMAS
export const dataIdSchema = z.number().int().positive().finite();
export const baseDataSchema = z.object({
id: dataIdSchema,
})
export const userSchema = baseDataSchema.extend({
name: z.string(),
})
export type BaseData = z.infer;
export type User = z.infer;
// CODE
//looking for optional attribs while 'id' still required
export type PaginationCursor = Partial & Pick;
export const createCursor = (record: T): PaginationCursor[] => {
/**
* Type '{ id: number; }' is not assignable to type 'PaginationCursor'.
* Type '{ id: number; }' is not assignable to type 'Partial'.ts(2322)
*/
const cursor: PaginationCursor = { id: record.id };
/**
* Type '{ id: 123; }' is not assignable to type 'PaginationCursor'.
* Type '{ id: 123; }' is not assignable to type 'Partial'.ts(2322)
*/
const cursor2: PaginationCursor = { id: 123 };
// just fine on declaration
const cursor3: PaginationCursor = { id: 123 };
const cursor4: PaginationCursor = { id: 123 };
/** cursor3:
* Type 'PaginationCursor' is not assignable to type 'PaginationCursor'.
* Type 'PaginationCursor' is not assignable to type 'Partial'.ts(2322)
*/
/** cursor4:
* Type 'PaginationCursor' is not assignable to type 'PaginationCursor'.
* Type 'PaginationCursor' is not assignable to type 'Partial'.ts(2322)
*/
return [cursor, cursor2, cursor3, cursor4];
}
< /code>
Проект - это Vite+React+ts
зависимости: < /p>
[*] "@emotion /react": "^11.13.3", < /li>
"@emorce /styled": "^11.13.0" /> "@fontsource/roboto": "^5.1.0",
[*] "@Hookform/Resolvers": "^3.9.0",
[*] "@mui/icons-material": "^6.4.8",
[*] "@mui/material": "^6.6",
[*] "@mui/material". /> "@mui/x-date-pickers": "^7.29.2",
[*] "@supabase/supabase-js": "^2.49.4",
[*] "Date-fns": "^4.1.0",
"I18Next": "^3.1. /> "i18next-browser-languagedeTector": "^8.1.0", < /li>
"Listlet": "^1.9.4", < /li>
"Lodash": "^4.17.21", < /li>
"React": "^18.1" /> "React-dom": "^18.3.1", < /li>
"Реакция-клетчатая форма": "^7.53.1", < /li>
"React-i18next": "^15.5.1", < /li>
"React-leaflet": "^4. />"socket.io-client ":"^4.8.1 ", < /li>
" Zod ":"^3.23.8 ", < /li>
" Zustand ":"^5.0.0 "< /li>
< /ul>
Подробнее здесь: https://stackoverflow.com/questions/796 ... ce-extends
Предполагаемые типы ZOD выглядят так, как будто они не выводя вывод о наследии (расширяются) ⇐ Javascript
Форум по Javascript
1748411851
Anonymous
Я создал этот файл, чтобы проверить поведение, которое мне нужно: < /p>
import { z } from "zod";
// SCHEMAS
export const dataIdSchema = z.number().int().positive().finite();
export const baseDataSchema = z.object({
id: dataIdSchema,
})
export const userSchema = baseDataSchema.extend({
name: z.string(),
})
export type BaseData = z.infer;
export type User = z.infer;
// CODE
//looking for optional attribs while 'id' still required
export type PaginationCursor = Partial & Pick;
export const createCursor = (record: T): PaginationCursor[] => {
/**
* Type '{ id: number; }' is not assignable to type 'PaginationCursor'.
* Type '{ id: number; }' is not assignable to type 'Partial'.ts(2322)
*/
const cursor: PaginationCursor = { id: record.id };
/**
* Type '{ id: 123; }' is not assignable to type 'PaginationCursor'.
* Type '{ id: 123; }' is not assignable to type 'Partial'.ts(2322)
*/
const cursor2: PaginationCursor = { id: 123 };
// just fine on declaration
const cursor3: PaginationCursor = { id: 123 };
const cursor4: PaginationCursor = { id: 123 };
/** cursor3:
* Type 'PaginationCursor' is not assignable to type 'PaginationCursor'.
* Type 'PaginationCursor' is not assignable to type 'Partial'.ts(2322)
*/
/** cursor4:
* Type 'PaginationCursor' is not assignable to type 'PaginationCursor'.
* Type 'PaginationCursor' is not assignable to type 'Partial'.ts(2322)
*/
return [cursor, cursor2, cursor3, cursor4];
}
< /code>
Проект - это Vite+React+ts
зависимости: < /p>
[*] "@emotion /react": "^11.13.3", < /li>
"@emorce /styled": "^11.13.0" /> "@fontsource/roboto": "^5.1.0",
[*] "@Hookform/Resolvers": "^3.9.0",
[*] "@mui/icons-material": "^6.4.8",
[*] "@mui/material": "^6.6",
[*] "@mui/material". /> "@mui/x-date-pickers": "^7.29.2",
[*] "@supabase/supabase-js": "^2.49.4",
[*] "Date-fns": "^4.1.0",
"I18Next": "^3.1. /> "i18next-browser-languagedeTector": "^8.1.0", < /li>
"Listlet": "^1.9.4", < /li>
"Lodash": "^4.17.21", < /li>
"React": "^18.1" /> "React-dom": "^18.3.1", < /li>
"Реакция-клетчатая форма": "^7.53.1", < /li>
"React-i18next": "^15.5.1", < /li>
"React-leaflet": "^4. />"socket.io-client ":"^4.8.1 ", < /li>
" Zod ":"^3.23.8 ", < /li>
" Zustand ":"^5.0.0 "< /li>
< /ul>
Подробнее здесь: [url]https://stackoverflow.com/questions/79641229/zod-inferred-types-look-like-theyre-not-inferring-the-inheritance-extends[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия