Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
Type 'string' is not assignable to type '{ model: { nodes: []; links: []; }; }'.ts(2322)

I'm new on typescript, here i have added types to a project of mine, it is giving me error on one of types at graph: "" : Type 'string' is not assignable to type '{ model: { nodes: []; links: []; }; }'.ts(2322)

The expected type comes from property 'graph' which is declared here on type 'InitialGraphArticleState'

any help/suggestion is appreaciated.

interface InitialGraphArticleState {
  graph: { model: { nodes: []; links: [] } };
  currentNode: string;
  currentLink: string;
  currentCameraNode: string;
  currentCameraLinks: [];
  floorplan: string;
}

const initialGraphArticleState: InitialGraphArticleState = {
  graph: "",
  currentNode: "",
  currentLink: "",
  currentCameraNode: "",
  currentCameraLinks: [],
  floorplan: "",
};

export function graphArticleReducer(
  state = initialGraphArticleState,
  action: graphArticleReducerAction
) {
  
}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In your initialGraphArticleState object, the property graph does not match the interface definition: You are basically a assigning a string to a property of type { model: { nodes: []; links: [] } }.

You can either change the object initialization as follow:

interface InitialGraphArticleState {
  graph: { model: { nodes: [], links: [] } };
  currentNode: string;
  currentLink: string;
  currentCameraNode: string;
  currentCameraLinks: [];
  floorplan: string;
}

const initialGraphArticleState: InitialGraphArticleState = {
  graph: { model: { nodes: []; links: [] } },
  currentNode: "",
  currentLink: "",
  currentCameraNode: "",
  currentCameraLinks: [],
  floorplan: "",
};

Or update your interface definition to allow a null graph object and initialize to that instead:

interface InitialGraphArticleState {
  graph: { model: { nodes: [], links: [] } } | null;
  currentNode: string;
  currentLink: string;
  currentCameraNode: string;
  currentCameraLinks: [];
  floorplan: string;
}

const initialGraphArticleState: InitialGraphArticleState = {
  graph: null,
  currentNode: "",
  currentLink: "",
  currentCameraNode: "",
  currentCameraLinks: [],
  floorplan: "",
};

Considering how you are using the graph property in the reducer, I would advise the first solution, otherwise you need to check that the property is not null before trying to use its properties.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda