A
arktype2mo ago
PIat

Adding comment to object key

Hello! What would be the right way to add comments to an object's key, like you do with /** */? I tried this, but it didn't work:
output: type({
/** Image id */
id: type('string').describe('Image id'),
})
output: type({
/** Image id */
id: type('string').describe('Image id'),
})
22 Replies
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
PIat
PIat2mo ago
Thank you! Good to know 👍
Dimava
Dimava2mo ago
Hmm @ssalbdivad looks like a regression since v1
ssalbdivad
ssalbdivad2mo ago
@Dimava I remember you had opened an issue related to this but I know in the general case it is not possible as @AlexWayne mentions, especially given the addition of parsed syntax for e.g. index signatures within keys
Dimava
Dimava2mo ago
ik general case is not possible but non-optionals did work well type.for (what was it again? I still forget it every time) may be better for those
ssalbdivad
ssalbdivad2mo ago
declare.type If it is possible to implement a solution that preserves them for required keys without sacrificing perf and ideally without duplicating a ton of code I would be open to merging that, it's just not something I want to commit to broadly since TS's rules around it aren't necessarily clear or well-documented either
Dimava
Dimava2mo ago
IIRC there was only a single working rule and it was "[K in keyof T as X] should use clean K in X when required " Gonna check how your code works
ssalbdivad
ssalbdivad2mo ago
Yeah it has to be a homomorphic mapped type but you can see why I'm not just not very keen on the idea of making guarantees around behavior like this based on the extent of what TS has officially guaranteed about it
Dimava
Dimava2mo ago
This should work, how do I bench
No description
ssalbdivad
ssalbdivad2mo ago
pnpm benchObject My intuition is that is not great since it adds an extra intersection to every object type And that EscapeToken comparison is not trivial not always correct (though it would still be an improvement to get it most of the time)
Dimava
Dimava2mo ago
+2.5%
No description
ssalbdivad
ssalbdivad2mo ago
That's not bad, I'd want to do some more testing though since those aren't really comprehensive enough on their own to give me a lot of confidence about a change of this scope. What about pnpm attest stats before and after the change
Dimava
Dimava2mo ago
hm
No description
ssalbdivad
ssalbdivad2mo ago
Yeah that's less encouraging plus what are the errors
Dimava
Dimava2mo ago
Okay, 4519 is my best result That's 7.6% up
Want results from more Discord servers?
Add your server