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
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 ) ); } }