Предполагаемые типы ZOD выглядят так, как будто они не выводя вывод о наследии (расширяются)Javascript

Форум по Javascript
Ответить Пред. темаСлед. тема
Anonymous
 Предполагаемые типы ZOD выглядят так, как будто они не выводя вывод о наследии (расширяются)

Сообщение 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>

Подробнее здесь: https://stackoverflow.com/questions/796 ... ce-extends
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Javascript»