AlexWayne
AlexWayne
Explore posts from servers
Aarktype
Created by AlexWayne on 1/31/2025 in #questions
configure({ onUndeclaredKey: 'delete' }) seems to allow extra properties through.
Thank you for all you do. I’m going to try to replace zod for Arktype at work this year. Wish me luck.
13 replies
Aarktype
Created by AlexWayne on 1/31/2025 in #questions
configure({ onUndeclaredKey: 'delete' }) seems to allow extra properties through.
Sorry posted and ran to lunch so on my phone.
13 replies
Aarktype
Created by AlexWayne on 1/31/2025 in #questions
configure({ onUndeclaredKey: 'delete' }) seems to allow extra properties through.
No description
13 replies
Aarktype
Created by AlexWayne on 1/31/2025 in #questions
configure({ onUndeclaredKey: 'delete' }) seems to allow extra properties through.
And maybe the docs should call that out, as it’s two files in the example but not clear why
13 replies
Aarktype
Created by AlexWayne on 1/31/2025 in #questions
configure({ onUndeclaredKey: 'delete' }) seems to allow extra properties through.
Ohh okay. Gotcha. That makes sense anyway in a real app. But doesn’t play well with just playing around.
13 replies
Aarktype
Created by PIat on 8/12/2024 in #questions
Adding comment to object key
I'm fairly certain this is impossible. Typescript doesn't give type authors any APIs to make sure these survive transformations.
33 replies
Aarktype
Created by AlexWayne on 7/29/2024 in #questions
using an const array as a source for a string literal union
nice. Thank you.
7 replies
Aarktype
Created by AlexWayne on 7/29/2024 in #questions
using an const array as a source for a string literal union
Nice. So the '===' just infers the type from what follows it?
7 replies
TtRPC
Created by AlexWayne on 6/14/2024 in #❓-help
v10 useQueries does not return a stable reference
Ended up with
function useMemoizedResultData<T>(results: { data: T }[]): T[] {
const previousResultData = useRef<T[]>([])
const resultData = results.map((result) => result.data)

if (areArraysEqual(previousResultData.current, resultData)) {
return previousResultData.current
}

previousResultData.current = resultData
return resultData
}

/** Returns true when `a` and `b` are arrays with perfectly identical contents. */
function areArraysEqual(a?: unknown[], b?: unknown[]): boolean {
if (a === b) return true
if (a?.length !== b?.length) return false
return !!a?.every((item, i) => item === b?.[i])
}
function useMemoizedResultData<T>(results: { data: T }[]): T[] {
const previousResultData = useRef<T[]>([])
const resultData = results.map((result) => result.data)

if (areArraysEqual(previousResultData.current, resultData)) {
return previousResultData.current
}

previousResultData.current = resultData
return resultData
}

/** Returns true when `a` and `b` are arrays with perfectly identical contents. */
function areArraysEqual(a?: unknown[], b?: unknown[]): boolean {
if (a === b) return true
if (a?.length !== b?.length) return false
return !!a?.every((item, i) => item === b?.[i])
}
Which feels like a bit of a hack, but it seems to work.
5 replies
TtRPC
Created by AlexWayne on 6/14/2024 in #❓-help
v10 useQueries does not return a stable reference
I guess trpc v11 and tanstack query v5 fix this with the combine option. Maybe I should focus on being able to upgrade instead
5 replies
TtRPC
Created by AlexWayne on 6/14/2024 in #❓-help
v10 useQueries does not return a stable reference
This does work, which means the data prop is stable
const foo = useMemo(() => {
console.log('memo recreated')
return results.map((result) => result.data?.id)
}, [results[0]?.data])
const foo = useMemo(() => {
console.log('memo recreated')
return results.map((result) => result.data?.id)
}, [results[0]?.data])
but I'm not seeing how to get a stable array of the data objects themselves
5 replies