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

377
Views
¿Cómo verifico el tipo de una variable dentro de una declaración `if`

Hay un problema en esta área.

 if (components[i] == **TextOptionType**) {

Estoy autodepurando un complemento para un programa llamado obsidiana.

~ObsidianDevLibrary.ts se encuentra en Importación de ~type.ts.

Hay un problema al referirse a TextOptionType como un valor.

¿Como puedo resolver esto?

tipo.ts

 export type TextOptionType = { [propName: string] : any, key: string, placeholder?: string, autoSave?: boolean, value?: boolean, onChange?: onChangeType, }

ObsidianDevLibrary.ts

 for (let i = 0; i < components.length; i++) { if (components[i] == TextOptionType) { componentsToReturn.push(this.addText(setting, components[i])) } }

Tal vez comparar TextOptionType con si es una gramática incorrecta, pero no sé la forma correcta.

Puede estar destinado a verificar que los datos que ingresan al componente estén formateados

https://github.com/KjellConnelly/obsidian-dev-tools

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

0

Defina una function de predicado de tipo que busque miembros conocidos de TextOptionType , así:

 function isTextOptionType( x: unknown ): x is TextOptionType { const whatIf = x as TextOptionType; return ( ( typeof whatIf === 'object' && whatIf !== null ) && ( typeof whatIf.key === 'string' ) && ( typeof whatIf.placeholder === 'string' || typeof whatIf.placeholder === 'undefined' ) && ( typeof whatIf.autoSave === 'boolean' || typeof whatIf.autoSave === 'undefined' ) && ( typeof whatIf.value === 'boolean' || typeof whatIf.value === 'undefined' ) && ( typeof whatIf.onChange === 'function' || typeof whatIf.onChange === 'undefined' ) ); }

Usado así:

 for( const c of components ) { if( isTextOptionType( c ) ) { componentsToReturn.push( this.addText( setting, c ) ); } }
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!