Class-validator in NestJS issue
Stack Overflow Forum » Typescript
by Bernard
56m ago
My ResponseEnhanced.dto.ts file : import { IsString, IsArray, IsPhoneNumber, ValidateNested, IsNotEmpty, IsIn } from 'class-validator'; import { Type } from 'class-transformer'; class LongTextResponseDto { @IsString() @IsNotEmpty() value: string; } class ShortTextResponseDto { @IsString() @IsNotEmpty() value: string; } class PhoneNumberResponseDto { @IsPhoneNumber() value: string; } class MultiSelectResponseDto { @IsArray() @IsString({ each: true }) @IsNotEmpty({ each: true }) value: string[]; } export class ResponseDto { @IsString() @IsNotEmpty() questionId ..read more
Visit website
Can I make Typescript narrow an object value type based on discriminated union key?
Stack Overflow Forum » Typescript
by 1valdis
56m ago
Playground link. I have a discriminated union of object types: export type ADiscriminatedUnion = { type: 'a', dataKeyA: number, anotherDataKeyA: number, } | { type: 'b', dataKeyB: number, anotherDataKeyB: number, } | { type: 'c', } type AllTypes = ADiscriminatedUnion['type']; I create an object, that maps some types (but not all) to a partial list of properties present in an object of that type: const DiscriminatedUnionTypeToListOfDataKeysMap = { a: ['dataKeyA'], b: ['dataKeyB', 'anotherDataKeyB'], } as const satisfies { [Type in AllTypes]?: Array< ..read more
Visit website
Setting the type of second parameter based on the value of the first parameter
Stack Overflow Forum » Typescript
by Neta Meta
56m ago
So basically if i call test with one of isText or isNumber strings it will decide what type to accept. type EvtType = 'isText' | 'isNumber'; function test(firstParam: EvtType , secondParameter: /*firstParam ===isText ? string : number*/) { //... } test('isText',2)// error test('isText', "hey")// works ..read more
Visit website
Typescript Global Type without "declare global"
Stack Overflow Forum » Typescript
by Aslan Mammadov
56m ago
This is not a problem, i am simply curiouos of how it is possible. I created simple generic type in my project and have been using it for days. Suddenly i noticed, that i never exported it from file and didn't import in file where i used it. It placed in src/types/returnComponentType.ts, not something like src/@types/global.d.ts, so tecnicaly it is not supposed to work. Did anyone face something similar or know why this happen? Generic Type Usage example ..read more
Visit website
Next.js Intercept Route displays on route a link is clicked from instead of first navigating to the parent route
Stack Overflow Forum » Typescript
by Stuart Mitchelhill
56m ago
I am new to next.js and am having trouble with intercept routes. What I am trying to achieve is a nested intercept route "latest/[slug]" that would display in a modal over the "latest" route template, however when there is a link from another route i.e. the homepage clicking on the "latest/[slug]" link here is displaying the modal over the homepage as opposed to navigation to "latest" and then displaying "latest/[slug]" in a modal there. I am just trying to resolve the issues with the intercept route for now so there is no modal logic and I am just dumping the slug for the route. Here is the c ..read more
Visit website
Type error initializing sequelize model with virtual datatype
Stack Overflow Forum » Typescript
by Dan Monego
2h ago
I'm trying to define a model in sequelize that uses a virtual datatype, but I'm getting a type error. This is my model definition: export const Contact = sequelize.define("contact", { firstName: DataTypes.STRING, lastName: DataTypes.STRING, fullName: { type: DataTypes.VIRTUAL, get(){ return `${this.firstName} ${this.lastName}`.trim()}, set() {throw "Set firstName, lastName instead!"} } }) However, the getter on the fullName field has a type error on the firstName and lastName properties. Both read Property 'firstName' does not exist on type 'Model<any, any>'. Can th ..read more
Visit website
Using transactions in tests w/ NestJS & TypeORM
Stack Overflow Forum » Typescript
by ibodi
2h ago
I want to write such a unit test file that each time I run it, I run an instance of the entire application. This is ensured by this part: module = await Test.createTestingModule({ imports: [AppModule], }).compile(); Then I wanted to clean up the database after each unit test. ChatGPT led me to the conclusion that I should use transactions. It suggested that I should use: beforeEach(async () => { await dataSource.query('BEGIN'); }); afterEach(async () => { await dataSource.query('ROLLBACK'); }); But it didn't want to work for me. Then after some chatting with the chat, I came t ..read more
Visit website
Cant initialize model in sequelize Typescript
Stack Overflow Forum » Typescript
by ntdoJanneck
2h ago
I'm trying to connect my Nodejs TypeScript Project to a MySQL database using Sequelize and Sequelize-Typescript, but I cant get sequelize to initialize my database model. Whenever I start the project, it throws the following error: TypeError: Cannot convert undefined or null to object at Function.getOwnPropertyDescriptor (<anonymous>) at /home/janneck/WebstormProjects/SchoolService/node_modules/sequelize-typescript/dist/model/column/column.js:18:131 at __esDecorate (/home/janneck/WebstormProjects/SchoolService/dist/models/documentType.model.js:13:40) at /home/janneck/Web ..read more
Visit website
Yup typescript image file validation
Stack Overflow Forum » Typescript
by lakhiwaladev
2h ago
import React from "react"; import { useForm } from "react-hook-form"; import { yupResolver } from "@hookform/resolvers/yup"; import * as yup from "yup"; interface MyFormType { image: FileList | null; } const defaultValues: MyFormType = { image: null, }; const validationSchema:yup.ObjectSchema<MyFormType> = yup.object({ image: yup.mixed<FileList|null>().nullable() }); const MyForm: React.FC = () => { const { register, handleSubmit, formState: { errors } } = useForm<MyFormType>({ resolver: yupResolver(validationSchema), }); const onSubmit = (data: MyFor ..read more
Visit website
Generating enum types with Hasura & @graphql-codegen
Stack Overflow Forum » Typescript
by bike38
3h ago
I'm using Hasura cloud to expose data from a PostgreSQL table My frontend is a Next.js app where I have configured graphql-codegen to type my queries: { schema: { [process.env.NEXT_PUBLIC_HASURA_BASE_URL]: { headers: { 'X-Hasura-Admin-Secret': '****', 'X-Hasura-Role': 'public', }, }, }, documents: [ './shared/**/*.tsx', ], ignoreNoDocuments: true, generates: { [`./shared/__generated/gql/`]: { preset: 'client', config: { avoidOptionals: true, skipTypename: false, sc ..read more
Visit website

Follow Stack Overflow Forum » Typescript on FeedSpot

Continue with Google
Continue with Apple
OR