jakemstar
jakemstar
TTCTheo's Typesafe Cult
Created by jairrard on 4/22/2023 in #questions
how tight should types be?
You want to do some sort of type narrowing so you can be certain that the properties exist. Here's the TS docs on that. https://www.typescriptlang.org/docs/handbook/2/narrowing.html One option is to create a common property on all these types in the union and check that value like this:
type Tasker =
{
_id: ObjectId;
name: string;
email: string;
kind: "someIdentifier"
}
| {
email: string;
kind: "anotherIdentifier";
}
| {
persona: string;
kind: "yetAnother";
};
type Tasker =
{
_id: ObjectId;
name: string;
email: string;
kind: "someIdentifier"
}
| {
email: string;
kind: "anotherIdentifier";
}
| {
persona: string;
kind: "yetAnother";
};
function getTaskerName(tasker: Tasker) {
if (tasker.kind === "someIdentifier") return tasker.name
}
function getTaskerName(tasker: Tasker) {
if (tasker.kind === "someIdentifier") return tasker.name
}
12 replies
TTCTheo's Typesafe Cult
Created by shikishikichangchang on 4/22/2023 in #questions
nextjs layout rerendering
3 replies
TTCTheo's Typesafe Cult
Created by Complexlity on 4/22/2023 in #questions
Receiving Contact/Feedback from Website to Email
https://www.smtpjs.com/ Has a pretty clean solution for this with a free tier limit of 100 emails/day.
10 replies