Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
.tsx files throw errors while .js files work fine

in react-native, when I try to pass parameters to functions/components/etc, typescript files will always complain and it won't work until I have specified the type which often is confusing and the code looks way more like spaghetti..

When using .js file with the same code, everything works fine. Also, there are no errors shown in VSCode when there are missing imports or wrong types being passed. Is there any proper way to handle this? Should I only use .tsx for react-native ? can I somehow get a sweet-spot between having errors with .tsx files and not having any Intellisense with .js files?

Btw: I dont need help fixing the errors in the pictures, I want to avoid that they're being shown as errors.

Thanks in Advance. passing parameters error example error

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You need to type those parameters since this file is TypeScript now.

I don't know the shape of navigation, route and user, but to get rid of the errors, you could type those values as any:

export function AuthStack({navigation, route}: any) {}

and

const [user, setUser] = useState<any>(null);
about 4 years ago · Juan Pablo Isaza Relatório

0

Files .js are just javaScript, jsx ("React syntax") can run in there or in a .jsx file. But .ts and .tsx are typeScript files, which means that your javaScript now would needs types for the code. You can read more about it on:

https://www.typescriptlang.org/

An easy way to solve the problem is the Ali Klein answer. Or actually use the right types for those variables. For exmaple: useState<string|null>(null);

If you don't want to use types, why not use .jsx instead .tsx for the files?

Another option would be use the comment //@ts-ignore over each line with type checking

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda