Benjamin
Benjamin
TTCTheo's Typesafe Cult
Created by Benjamin on 12/29/2023 in #questions
Global variable `Astro` type is `any` when migrating from v3 to v4
I had the help of an Astro team member, the bug has been identified, there is like a loop when inferring getStaticPaths. Here are two workarounds: - Explicit the type returned by getStaticPaths instead of inferring it; - Use directly import.meta.glob instead of Astro.glob.
6 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 12/29/2023 in #questions
Global variable `Astro` type is `any` when migrating from v3 to v4
6 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 12/29/2023 in #questions
Global variable `Astro` type is `any` when migrating from v3 to v4
So it happens only when I use the global variable inside getStaticPaths. If I rename the function, it works! 🤯
6 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 9/12/2023 in #questions
shadcn/ui DropdownMenu component not working with Astro
It was not working because the component was server-side. I added the client:load property to my component in the .astro file so it's loaded client-side.
6 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 9/12/2023 in #questions
shadcn/ui DropdownMenu component not working with Astro
I managed to get rid of the error by using the DropdownMenu component in a .tsx file instead of .astro file but now the trigger don't even work. 😅 🔫
6 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 9/12/2023 in #questions
shadcn/ui DropdownMenu component not working with Astro
I shared a repository: https://github.com/benjamin-guibert/shadcn/tree/main You juste have to pnpm install and pnpm dev
6 replies
TTCTheo's Typesafe Cult
Created by Lumberjack on 8/22/2023 in #questions
dynamic unit testing
Yup, tests should always be deterministic: always know what your inputs and expected outputs are.
13 replies
TTCTheo's Typesafe Cult
Created by ray1sx on 8/12/2023 in #questions
TypeScript complaining even the code is correct?
By the way, don't forget to specify typescript when you write code in Discord so it gets syntax highlighted 😉
6 replies
TTCTheo's Typesafe Cult
Created by ray1sx on 8/12/2023 in #questions
TypeScript complaining even the code is correct?
I don't have the context of your use case, but maybe groupBy would be interesting: https://lodash.com/docs/4.17.15#groupBy
6 replies
TTCTheo's Typesafe Cult
Created by ray1sx on 8/12/2023 in #questions
TypeScript complaining even the code is correct?
It is because it is unsafe. I assume you're using a Map, which is a good thing, you should take the advantage of has(), get(), set()... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
6 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
but why if I only have one condition (value !== undefined), it manages, but not 2?
24 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
My post purpose was mainly to understand why TypeScript doesn't understand
24 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
Yeah I think the as string is the most readable 😅
24 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
yeah...
24 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
It was not exactly my use case, I am calling another function that takes a string as parameter. It works but it means I have to repeat the function call twice. Not ideal but maybe better than as string, I don't know. I guess that's the 2 solutions. ¯\_(ツ)_/¯
24 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
I have to add as string and I hate that 😢
24 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
Nope, you're changing the logic, I only want to throw if neither are defined (= both undefined). That's why TS should know at least one of them is defined and therefore the result is never undefined.
24 replies
TTCTheo's Typesafe Cult
Created by Benjamin on 8/9/2023 in #questions
Why the infered type of this function is `string | undefined`?
Even a simple version returns string | undefined:
export const myFunction = (value1?: string, value2?: string) => {
if (value1 == undefined && value2 == undefined) {
throw new Error("No value provided.");
}

return value1 != undefined ? value1 : value2;
};
export const myFunction = (value1?: string, value2?: string) => {
if (value1 == undefined && value2 == undefined) {
throw new Error("No value provided.");
}

return value1 != undefined ? value1 : value2;
};
24 replies
TTCTheo's Typesafe Cult
Created by Lopen on 8/8/2023 in #questions
best practices to throw error on backend
Haha I understand, but at least it provides documentation without writing documentation 😁
43 replies
TTCTheo's Typesafe Cult
Created by Lopen on 8/8/2023 in #questions
best practices to throw error on backend
For me the last example you provided is good enough, it's clear
43 replies