cornflour
cornflour
Explore posts from servers
TTCTheo's Typesafe Cult
Created by cornflour on 3/14/2024 in #questions
Dynamic record with value type depending on key suffix
I need to create a list of records for a scatter chart data with error bars. There can be an arbitrary number of datasets in this chart. The record contains a x key representing the x-axis position (value type number), ${datasetID}_value key representing the value of the dataset with given id (value type number) and ${datasetID}_errors representing the errors of the value at this position (type [number, number]). I want to be able to push a valid record into the list without TS errors like so
type DataRecord = ??? // TODO: define this
type DataList = DataRecord[]

const myData: DataList = []

// goal is for this to work
myData.push({
x: 0,
[`${id1}_value`]: 1,
[`${id1}_error`]: [0, 1],
})

// this should also work
myData.push({
x: 0,
[`${id1}_value`]: 1,
[`${id1}_error`]: [0, 1],
[`${id2}_value`]: 2,
[`${id2}_error`]: [1, 1],
})
type DataRecord = ??? // TODO: define this
type DataList = DataRecord[]

const myData: DataList = []

// goal is for this to work
myData.push({
x: 0,
[`${id1}_value`]: 1,
[`${id1}_error`]: [0, 1],
})

// this should also work
myData.push({
x: 0,
[`${id1}_value`]: 1,
[`${id1}_error`]: [0, 1],
[`${id2}_value`]: 2,
[`${id2}_error`]: [1, 1],
})
I'm not sure if this is possible since the prop inside the push() call is being treated as {x: number; [x: string]: number | number[]}, so I'd love to get help on this, thank you so much. Here is my progress so far: TS Playground
9 replies
TTCTheo's Typesafe Cult
Created by cornflour on 10/9/2023 in #questions
Button with 4 triangles at 4 corners
No description
5 replies
TTCTheo's Typesafe Cult
Created by cornflour on 6/21/2023 in #questions
implement discord-like account switching
I want the user to be able to sign in with multiple accounts, then switch between them similar to how you switch account in discord. However, I could not find any information on how to implement this with next-auth (or just implementing it in general). How can I implement this? Tysm in advance! For additional context, I am using appdir, and there is an external server that I will be authenticating against, which returns me a JWT when the user signs in (me sending them a request with username & password). This server is outside of my control.
8 replies
TTCTheo's Typesafe Cult
Created by cornflour on 6/13/2023 in #questions
Websocket with Next appdir/RSC?
With the new RSC paradigm, how would we write a React app with Websocket (say for example a discord clone)? Do we still do it similar to how it has always been done or is there a new (better) pattern for these types of apps? How would this change if I already have a functional backend vs just starting everything from scratch?
9 replies
TTCTheo's Typesafe Cult
Created by cornflour on 2/22/2023 in #questions
infinite streaming response with tRPC?
I want to create a tRPC endpoint which calls to the docker log API (https://docs.docker.com/engine/api/v1.41/#tag/Container/operation/ContainerLogs). This API can return an infinite stream of data (when setting follow=true) to send data in real time when there's a new log. I am not sure how to send back this streaming data to the client side so that the app can display the logs in real time. I am aware of the existence of tRPC subscription (https://trpc.io/docs/subscriptions) and it seems like that will be what i need, but I don't know how to connect the pieces together for my case. Thank you so much in advance.
1 replies
TTCTheo's Typesafe Cult
Created by cornflour on 11/12/2022 in #questions
is Astro SPA a good idea?
Okay the plan is this (say we are making a dashboard or some other form of web apps, ignoring SEO stuff): - Create an astro project - have only a [...app].astro file in the routing, which contain an <App/> react component - handle everything else inside <App /> like a classic React SPA app It's probably not the type of things astro was built for, but what are the actual downsides of this I can expect versus other ways of making the same app (say t3 stack for e.g.)?
70 replies
TTCTheo's Typesafe Cult
Created by cornflour on 10/26/2022 in #questions
React Query + Next 13 + Vercel?
Has anyone been able to deploy a site with RQ and Next 13 to Vercel? I am able to use RQ locally, both in dev and build, but when deploying to vercel, the page would return error 500. Not sure what could be the cause for me...
6 replies