Clearly, I need to add CoPilot to my VSCode setup.
Clearly, I need to add CoPilot to my VSCode setup.
So in theory if you keep fns like leftPad in your repo and it's so easy to do, it would be more future proof, secure, and flexible for the future.
You know you can write "export function le" in TypeScript and it will give you
export function leftPad(value: string, length: number, char: string = '0') {
return value.padStart(length, char);
}Although this here is imperfect since it didn't add types, so still room for improvement. It didn't add types maybe because it wasn't passed the context about being in the .ts file
But I don't have to context switch to Google, or install the library just for this fn.
Or "export function capi..."
Would go to
export function capitalize(value: string) {
return value.charAt(0).toUpperCase() +
value.slice(1);
}
Any CRUD related boilerplate, like let's say I want to do notes,I start typing type Note = ... It will autofill the usual fields/types for me, which I can then edit to my use-case.
E.g it autofilled
type Note = {
id: string;
title: string;
content: string;
}
And then I write const validationSchema = ...If I have yup imported, it will give me:
yup.object().shape({ title: yup.string().required(), content: yup.string().required() });
Again, I would tweak it a bit to my usecase, if needed, and then I will write
const handleCreateNote = ...
It will give me:
const handleCreateNote = async (req, res) => {
try {
const note = req.body as Note;
await validationSchema.validate(note);
const createdNote = await NoteService.create(note);
res.status(201).json(createdNote);
} catch (error) {
res.status(400).json({ error: error.message });
}
}
Then I tweak it if needed, and it can create similar handlers for other CRUD actions.E.g. here my first though is that I probably want to not use try catch, and not throw. And maybe return 422 with exact validation information.
But once I give it an example of how I want to do it, it would be able to follow it for other endpoints.