Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
¿Cómo asignar mi clave de cadena a algunos posibles valores de enumeración?

tengo la siguiente interfaz

 export interface AuctionMOLQueryParams { filterAuctionDirection?: string; }

porque filterAuctionDirection puede ser uno de los tres valores posibles que configuré para ser enum

 export enum ProductDirection { upwards = 'A01', downwards = 'A02', all = 'All' } export interface AuctionMOLQueryParams { filterAuctionDirection?: ProductDirection; }

el problema es que ahora cuando trato de usar este tipo de objeto

 let queryParams: AuctionMOLQueryParams = { filterAuctionDirection: ProductDirection.all, }

Los tipos de propiedad 'filterAuctionDirection' son incompatibles. El tipo 'cadena' no se puede asignar al texto fuerte de tipo 'ProductDirection'

Como puedo resolver esto ? ¿Cómo puedo mapear mi filterAuctionDirection para que sea uno de estos tres valores y el tipo de seguridad seguirá funcionando correctamente?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

TS2717: Subsequent property declarations must have the same type. Property 'filterAuctionDirection' must be of type 'string', but here has type 'ProductDirection'.

Si entendí su pregunta correctamente, está definiendo la interfaz AuctionMOLQueryParams dos veces.
Inicialmente, define el campo filterAuctionDirection como una string , pero luego intenta marcarlo como ProductDirection .

Si está intentando restringir un tipo de variable de una interfaz declarada externamente (en este ejemplo AuctionMOLQueryParams ), debe definir una nueva interfaz que se extienda.

Ejemplo para su caso de uso:

 export interface AuctionMOLQueryParams { filterAuctionDirection?: string; } export enum ProductDirection { upwards = 'A01', downwards = 'A02', all = 'All' } export interface MyAuctionMOLQueryParams extends AuctionMOLQueryParams { filterAuctionDirection?: ProductDirection; } let queryParamsValid1: MyAuctionMOLQueryParams = { filterAuctionDirection: ProductDirection.all, } let queryParamsInvalid2: MyAuctionMOLQueryParams = { filterAuctionDirection: "My", } let queryParamsInvalid1: MyAuctionMOLQueryParams = { filterAuctionDirection: "All", }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!