ts, mjs, js

When do I use which file extensions?
17 Replies
Vincent Udén
Vincent Udén2y ago
.ts is for typescript, the others for javascript. For the difference between .mjs and .js see: https://stackoverflow.com/questions/57492546/what-is-the-difference-between-js-and-mjs-files
Stack Overflow
What is the difference between .js and .mjs files?
I have started working on an existing project based on Node.js. I was just trying to understand the flow of execution, where I encountered with some *.mjs files. I have searched the web where I found
shikishikichangchang
Let's say I have some utils functinos Should I put them in .js or .ts files?
Vincent Udén
Vincent Udén2y ago
Is this using the t3 stack? Or on projects in general?
Vincent Udén
Vincent Udén2y ago
The t3 stack uses typescript, as such the files should .ts
shikishikichangchang
const yyyymmdd = () => {
const mm = this.getMonth() + 1; // getMonth() is zero-based
const dd = this.getDate();
return [
this.getFullYear(),
(mm > 9 ? "" : "0") + mm,
(dd > 9 ? "" : "0") + dd,
].join("-");
};
const yyyymmdd = () => {
const mm = this.getMonth() + 1; // getMonth() is zero-based
const dd = this.getDate();
return [
this.getFullYear(),
(mm > 9 ? "" : "0") + mm,
(dd > 9 ? "" : "0") + dd,
].join("-");
};
Vincent Udén
Vincent Udén2y ago
Side note: nothing is stopping you from using .js, that will also work. But since it is typescript, the extension should indicate that
shikishikichangchang
I have this function that I apply to the Date prototype, it keeps giving me the error "Object is not defined" for the keyword "this" By using .js, wouldn't that just completely forfeit the idea of trpc
Matvey
Matvey2y ago
there is no this in arrow functions Don't do this, just have a function that has date as input
shikishikichangchang
ok thanks! My react component takes in a response object, how do I (do I need to) specify the type in the argument?
export default function Portfolio({ _res = null, currentUser = null })
export default function Portfolio({ _res = null, currentUser = null })
Im a ocmplete TS newbie
Matvey
Matvey2y ago
React.FC<{ res: Response, currentUser: User | null }> is the type or something like this
shikishikichangchang
Where would I get the Response and User? I think it should come from Zod no?
Matvey
Matvey2y ago
there is a useSession hook in NextAuth for getting the current user
shikishikichangchang
I thought there's a way to infer the type
Matvey
Matvey2y ago
You can infer all types, yes
shikishikichangchang
Do you know of a tutorial that shows this my understanding is all the types can be inferred from schema.prisma Am I mistaken?
Samathingamajig
.ts because you'll be writing them in typescript files
Want results from more Discord servers?
Add your server