how to fix typescript error
I have this code:
but I'm getting this error:
how would I fix this? I would have thought that
config
would be a union type and not an intersect type6 Replies
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
ts isnt smart enough to know dbType and typeConfig.type are the same
therefore typeConfig isnt discriminated
as a side note it seems like youre trying to get fancy with ts typing. my experience with that has been..... frustrating. TS lets you describe a ton of things in compile-time types but:
1) the typings themselves arent always elegant or readable to most people
2) types that are too restrictive can require writing your code in a more convoluted way in order for the compile-time checks to work
3) getting the types really really correct can take a long time
its possible im just not that good at ts, but this has been my overal experience trying to get ts to do more than just checking structure
thank you so much! I'd be all for a simpler less fancy way if possible. this is the version that I just landed on.
I updated it to this and am now having another issue:
the thing is the code as is has no errors but the version that this is based off of is failing
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
(next time make it a ts playground so its easier to look at btw)
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.