bedesqui
bedesqui
TTCTheo's Typesafe Cult
Created by bedesqui on 3/29/2024 in #questions
How to change refType in forwardRef based on prop?
No description
2 replies
TTCTheo's Typesafe Cult
Created by bedesqui on 6/8/2023 in #questions
Running before unmount on server components??
is there a way to wrap a react server component in a function that passes props to it and call something after component is dismounted or something? I know in client components I can make use of useEffect to call stuff before component is dismounted, but not sure how to do the same for server components. what we basically want to do is: 1. create instance of a thing 2. make it available to the component (could be a hook or props , doesn't matter) 3. make sure that the thing executes a function before the component unmounts
14 replies
TTCTheo's Typesafe Cult
Created by bedesqui on 2/28/2023 in #questions
get rid of Symbol iterator in autocomplete
Hi TS nerds, I'm in dire need of help; For a bit of context, I have a function that returns a tuple: const [hej, do] = myFunc(), and I'm looking to allow an object being returned by the same function: const obj = myFunc() // obj.hej and obj.do exist. for WAY more accurate code, see: https://github.com/bdsqqq/try/pull/10 My solution of choice rn would be:
export const trytm = async <T>(
promise: Promise<T>,
): Promise<TryResult<T>> => {
const getResult = (data: T | null, error: Error | null) => ({
data,
error,
[Symbol.iterator]: function* () {
yield this.data;
yield this.error;
}
})
try {
const data = await promise;
return getResult(data, null);
} catch (throwable) {
if (throwable instanceof Error) {
return getResult(null, throwable);
}

throw throwable;
}
};
export const trytm = async <T>(
promise: Promise<T>,
): Promise<TryResult<T>> => {
const getResult = (data: T | null, error: Error | null) => ({
data,
error,
[Symbol.iterator]: function* () {
yield this.data;
yield this.error;
}
})
try {
const data = await promise;
return getResult(data, null);
} catch (throwable) {
if (throwable instanceof Error) {
return getResult(null, throwable);
}

throw throwable;
}
};
But this makes the autocomplete of the object include data, error AND Symbol... Is there any way to not have Symbol there??
3 replies
TTCTheo's Typesafe Cult
Created by bedesqui on 11/18/2022 in #questions
Make an object with the same structure but modified values
I'm trying to do some cool stuff with .mdx as strings being parsed in getStaticProps and got to an ok point but everything went to shit when I tried to put those strings into an object since I need to serialize them and want to keep the object structure for that sweet autocomplete in the frontend. Long context out of the way, let's say I have:
const obj = {
something: "...",
somethingNested: {
iLove: "...",
typeSafety: "..."
}
}
const obj = {
something: "...",
somethingNested: {
iLove: "...",
typeSafety: "..."
}
}
How should I go about making another object, with the same structure and keys but where every string got passed to a serialize function I have? I tried something like
const recurse = (item: Object | string) => {
if(typeof item !== 'string'){
const keys = Object.keys(item);
keys.forEach(key => recurse(item[key]));
// I don't know how I should loop through the items in a way that would allow me to return the key and value correctly here 😭
} else {
// I don't know how to return the result to the right key here 😭
return serialize(item)
}
}
const recurse = (item: Object | string) => {
if(typeof item !== 'string'){
const keys = Object.keys(item);
keys.forEach(key => recurse(item[key]));
// I don't know how I should loop through the items in a way that would allow me to return the key and value correctly here 😭
} else {
// I don't know how to return the result to the right key here 😭
return serialize(item)
}
}
but kept going in circles with no success Hope everything here made sense because I really need help with this
6 replies
TTCTheo's Typesafe Cult
Created by bedesqui on 10/7/2022 in #questions
Move a domain to Vercel??
I'm currently using namecheap to register my domain and just pointing it to vercel to manage subdomains and that kind of stuff there. And since my domain is expiring soon I'm thinking about transferring it. Does anyone have experience on transferring a domain to Vercel? I didn't find a lot in about pricing other than "registering is usually 20 bucks" so I'd love to hear what yall know/think about it. Also, any other good providers??
22 replies