Z
Zod16mo ago
Scott Trinh

Time to fork the language server 🏃♂

Time to fork the language server! 🏃‍♂️ 💨
26 Replies
Sikari
Sikari16mo ago
I don't remember if this does it: https://github.com/yoavbls/pretty-ts-errors
Scott Trinh
Scott Trinh16mo ago
It doesn't
Sikari
Sikari16mo ago
Aw shame
Gludek
Gludek16mo ago
Tbf I would appreciate if this would make list that can be opened to see more of the types, like in file explorer
Scott Trinh
Scott Trinh16mo ago
Yeah, I honestly would love a huge expanded view of types because I'm often dealing with pretty gnarly types in my dayjob. bonus points for "Go to definition" of mapped types, too. Basically something that treats the type-level language as a first-class concept and allows exploration the same as the value-level language
Gludek
Gludek16mo ago
What annoys me the most is that in errors it doesn't truncate the types so much leading to huge error messages that are barely readable
Scott Trinh
Scott Trinh16mo ago
Yeah, I wish it did like:
Foo is not assignable to Bar
Baz is not assignable to Qux
string is not assignable to number
Foo is not assignable to Bar
Baz is not assignable to Qux
string is not assignable to number
So basically hide the verbose types using their names until you get to the final line and then show what primitive is conflicting.
Gludek
Gludek16mo ago
No description
No description
Scott Trinh
Scott Trinh16mo ago
I know it can't do that all the time due to structural typing (there might be multiple names for the same structure), but maybe in certain circumstances it could do that.
Gludek
Gludek16mo ago
Somebody give me the option to click on that ... 12 more ...! I find it that often in errors something like
Type1: {
type1A: {...}
} is not assignable to
Type2: {
type2B: string
}
Type1: {
type1A: {...}
} is not assignable to
Type2: {
type2B: string
}
would be enough. Just get to the element that collides. You can detect what it is! I don't need to know the whole type of type1A
Scott Trinh
Scott Trinh16mo ago
The problem is that the language server only really knows how to work with plain text. Wait, what would you want it to show in this case?
Gludek
Gludek16mo ago
Currently the error would be
Type1: { type1A: { field1:string, field2: string} } is not assignable to Type2: { type2B: string } }
Type1: { type1A: { field1:string, field2: string} } is not assignable to Type2: { type2B: string } }
or something like this if there's more fields it would be lot longer, but I find it that more often than not I only would need at the fields that causes issues OR the parent fields/types
Scott Trinh
Scott Trinh16mo ago
I'm curious because normally you wouldn't actually have Type1 and Type2 It would just be:
{ type1A: { field1:string, field2: string} } is not assignable to { type2B: string } }
{ type1A: { field1:string, field2: string} } is not assignable to { type2B: string } }
Gludek
Gludek16mo ago
Type '{ id: string; createDate: Date; piiData: { id: number; createDate: Date; email: string; phoneNumber: string; phonePrefix: { id: number; phonePrefix: string; country: string; }; profilePicUrl: string; firstname: string; surname: string; }; identityServerId: string; permissionsArray: number[]; patientBasicData: { ...;...' is missing the following properties from type '{ visitTime: Date; visitPlace: number; visitType: number; drugsPrescribedOnVisit: { name: string; dosage: string; frequency: string; drugApplication: number; }[]; visitDuration: number; doctor?: string | ... 1 more ... | undefined; patientCode?: string | ... 1 more ... | undefined; recommendationsDesc?: string | ......': visitTime, visitPlace, visitType, drugsPrescribedOnVisit, visitDurationts(2739)
Type '{ id: string; createDate: Date; piiData: { id: number; createDate: Date; email: string; phoneNumber: string; phonePrefix: { id: number; phonePrefix: string; country: string; }; profilePicUrl: string; firstname: string; surname: string; }; identityServerId: string; permissionsArray: number[]; patientBasicData: { ...;...' is missing the following properties from type '{ visitTime: Date; visitPlace: number; visitType: number; drugsPrescribedOnVisit: { name: string; dosage: string; frequency: string; drugApplication: number; }[]; visitDuration: number; doctor?: string | ... 1 more ... | undefined; patientCode?: string | ... 1 more ... | undefined; recommendationsDesc?: string | ......': visitTime, visitPlace, visitType, drugsPrescribedOnVisit, visitDurationts(2739)
Error I just created
Scott Trinh
Scott Trinh16mo ago
if it was nested in an object, you can look up one level and see what property of the object it is referring to (if it's not hidden!), but I'm exactly complaining that it doesn't (and in a lot of cases can't) show you the type name. right: no type names. Just the type literals. In a perfect world, I would want that to be:
Type 'Foo' is missing the following properties from type 'Bar': visitTime, visitPlace, visitType, drugsPrescribedOnVisit, visitDurationts(2739)
Type 'Foo' is missing the following properties from type 'Bar': visitTime, visitPlace, visitType, drugsPrescribedOnVisit, visitDurationts(2739)
Gludek
Gludek16mo ago
oh yeah, it should be possible, no? It's just relocation of strings
Scott Trinh
Scott Trinh16mo ago
Nope, because TypeScript uses structural typing so it might be any type that has that shape. I think the language server could do a better job with this, though. If you use classes/functions, you get names here, but that's not idiomatic for just raw data.
Gludek
Gludek16mo ago
ah fair, anyway gtg I need to clean up house and work a little more lol I'm still a newbie to TS, I only started actually working in february, and most of my time is spent fighting with react 😐
Scott Trinh
Scott Trinh16mo ago
ahh, well, welcome, glad to have you here with us.
Sikari
Sikari16mo ago
I personally hate how the types can be broader than their type (back to the structural typing point), but then again I guess things like Object.keys works around this by not assuming the type is exactly of T That sounds weird, what I mean is that shape of an object can be broader than T And because of that we get things like Object.keysjust return string[] instead of keyof T
Scott Trinh
Scott Trinh16mo ago
Yep. Structural typing (and to some extent subtyping) is why TypeScript is popular, but it's a big hinderance to the type-system itself in my experience.
Sikari
Sikari16mo ago
I wish it was a keyword or something :(
Gludek
Gludek16mo ago
Thanks, I'm glad I heard about zod from Matt Pocock. Watched video "ah cool", then started working "okay, what this package was?" I like working, since it doesn't allow for "do and forget", but man, do I hate my current project. Somehow there was nothing, but also hhad to work with some weird code because for some reason I'm the only frontend dev. It needs serious teardown and refactor, but no time to do it. previous dev used redux store for caching for some reason, and created weird promise helper, that is awful to use
Scott Trinh
Scott Trinh16mo ago
Welcome to industry 😬 ! Unless you're the first engineer being hired at a startup, or a principal starting a new greenfield project at an established company, you'll always be walking into something with a lot of technical debt and compromises and outdated practices and failed experiements. And if you are the first engineer, or a principal starting a greenfield, you'll be the one generating the tech debt and weird failed experiments for some other poor dev to scratch their head about.
Gludek
Gludek16mo ago
I mean the project was started by someone 3/4 levels (as in school years) lower than me, around 6 months beforehand. AFAIK they also are junior and were without mid/senior to overlook what they are doing. This whole project is a mess organization wise. Everything somehow works. And I somehow know enough about what I did to proceed, but before we enter into next stage there's a need to rethink and rework most of the stuff. Starting with database structure, endpoints and what exactly is needed. I started to redo some endpoints with tanstack query to fix caching issues, but every time I encounter then problems with data structure 🙂 and i'm 100% NOT writing things the "proper" way. I notice some code I wrote especially at the start that is full of holes, but no time to fix I just need 1 more person so we can do both fixing and introducing new stuff at similar pace and not one or the other
Want results from more Discord servers?
Add your server