AI CodingThrive Editorial

25 prompts de IA para programadores JavaScript

Os erros JavaScript escondem-se frequentemente nas fronteiras entre tipos, operações assíncronas e estados do navegador.

14 min de leitura
Espaço de trabalho de um programador JavaScript com percursos que representam tarefas assíncronas.

Versão breve

  • Os erros JavaScript escondem-se frequentemente nas fronteiras entre tipos, operações assíncronas e estados do navegador. Estes prompts centram-se numa dessas fronteiras e exigem um teste executável.
  • Nunca cole credenciais, dados privados de clientes ou repositórios proprietários completos num assistente não autorizado. Execute os comandos e os testes sugeridos no seu ambiente. Uma alteração plausível não comprova que funciona.

Os erros JavaScript escondem-se frequentemente nas fronteiras entre tipos, operações assíncronas e estados do navegador. Estes prompts centram-se numa dessas fronteiras e exigem um teste executável.

Nunca cole credenciais, dados privados de clientes ou repositórios proprietários completos num assistente não autorizado. Execute os comandos e os testes sugeridos no seu ambiente. Uma alteração plausível não comprova que funciona.

Como utilizar esta coleção

Escolha a tarefa mais próxima do seu trabalho. Copie o prompt, substitua a cena genérica ou o contexto de código pelos seus dados e mantenha as restrições que ajudam a avaliar o resultado. Altere uma variável de cada vez para identificar o que melhorou.

A abordagem segue o guia de engenharia de prompts do GitHub Copilot: forneça contexto concreto e examine o resultado sem assumir que um primeiro rascunho bem apresentado está correto.

Prompts de diagnóstico

Este conjunto centra-se em o diagnóstico. Forneça o seu código real e o comando de teste antes de aceitar a resposta.

1. Um caminho de rejeição de uma Promise

Help with a promise rejection path in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

2. Uma closure desatualizada num gestor de eventos

Help with a stale closure in an event handler in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

3. Um campo de pesquisa com debounce

Help with a debounced search field in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

4. Um erro de alteração de um array

Help with an array mutation bug in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

5. Uma análise incorreta de uma data

Help with an incorrect date parse in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

6. Um timeout numa operação fetch

Help with a fetch timeout in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

7. Uma migração de armazenamento local

Help with a local-storage migration in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

8. Uma fuga de event listeners

Help with an event listener leak in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

9. Um gestor de teclado para acessibilidade

Help with an accessibility keyboard handler in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

Asynchronous event paths and browser state timeline on a developer screen.

10. Um erro de importação ESM

Help with an ESM import error in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

Prompts de implementação

Este conjunto centra-se em a implementação. Forneça o seu código real e o comando de teste antes de aceitar a resposta.

11. Um caminho de rejeição de uma Promise

Help with a promise rejection path in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

12. Uma closure desatualizada num gestor de eventos

Help with a stale closure in an event handler in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

13. Um campo de pesquisa com debounce

Help with a debounced search field in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

14. Um erro de alteração de um array

Help with an array mutation bug in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

15. Uma análise incorreta de uma data

Help with an incorrect date parse in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

16. Um timeout numa operação fetch

Help with a fetch timeout in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

17. Uma migração de armazenamento local

Help with a local-storage migration in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

Three-step code workflow: brief the work, inspect the result, edit and verify.

18. Uma fuga de event listeners

Help with an event listener leak in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

19. Um gestor de teclado para acessibilidade

Help with an accessibility keyboard handler in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

20. Um erro de importação ESM

Help with an ESM import error in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

Prompts para testar os limites

Este conjunto centra-se em os testes dos limites. Forneça o seu código real e o comando de teste antes de aceitar a resposta.

21. Um caminho de rejeição de uma Promise

Help with a promise rejection path in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

22. Uma closure desatualizada num gestor de eventos

Help with a stale closure in an event handler in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

23. Um campo de pesquisa com debounce

Help with a debounced search field in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

24. Um erro de alteração de um array

Help with an array mutation bug in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

25. Uma análise incorreta de uma data

Help with an incorrect date parse in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

O que verificar antes de utilizar o resultado

Nunca cole credenciais, dados privados de clientes ou repositórios proprietários completos num assistente não autorizado. Execute os comandos e os testes sugeridos no seu ambiente. Uma alteração plausível não comprova que funciona.

Se o resultado não cumprir a tarefa, encurte o prompt e indique o facto ou a restrição em falta. Guarde a versão utilizada para que o recurso final ou a alteração de código possam ser reproduzidos.

Leituras adicionais

Continue com um guia relacionado

Ponha em prática

O seu próximo passo

Tem uma pergunta ou uma correção?

Contactar a Thrive

Continuar a ler

Mais artigos do diário

Todos os artigos