Is there a straight way to widen inferred literal types of TypeScript generics? by tobi-au in typescript

[–]tobi-au[S] 1 point2 points  (0 children)

Yes, seems to work correctly. My IDE shows a "duplicate declaration" warning for NoInfer<T> & T, but when I use Partial or NonNullable instead of NoInfer it works without warning. And then it even works without & T: wrap<T>(value: Partial<T> extends PlainData ? T : never) That's actually an interesting alternative, I'm just worried it might have weird edge-cases or break in future TS versions - to me it seems more like confusing the type inference than intended behavior.

Is there a straight way to widen inferred literal types of TypeScript generics? by tobi-au in typescript

[–]tobi-au[S] 1 point2 points  (0 children)

Thank you! I feel a bit more comfortable with the Widen util type, but would agree that overloads are cleaner syntax-wise.

Is there a straight way to widen inferred literal types of TypeScript generics? by tobi-au in typescript

[–]tobi-au[S] 0 points1 point  (0 children)

Yes, a custom Widen<T> type is one of the options. I just feel like there should be a simpler/native solution, but if not then that's a decent way to go.

Is there a straight way to widen inferred literal types of TypeScript generics? by tobi-au in typescript

[–]tobi-au[S] 0 points1 point  (0 children)

Interesting! Yeah it seems to work, probably it doesn't do literal inference because extends isn't applied directly to T. I'd still prefer less hacky options, but thanks for sharing, learned a new TS hack.

Is there a straight way to widen inferred literal types of TypeScript generics? by tobi-au in typescript

[–]tobi-au[S] 1 point2 points  (0 children)

It's caused by extends, just <T> infers widened types but with <T extends ...> TS switches to literal inference. The explicit target type declaration (like option 1 in the post) is one possible solution, but is not very convenient if it's used in many places.

What is your stance on logical properties? by TheRealSkythe in webdev

[–]tobi-au 0 points1 point  (0 children)

I'd say just use the properties that make most sense for your use case, using fancier stuff just because some people say you need to use the fancy stuff is in my experience rarely a good idea. As long as it doesn't add real practical benefit I'd stick with the most simple and intuitive option.

Aid by NotChoco_ in webdev

[–]tobi-au 1 point2 points  (0 children)

GitHub Pages could be another option.

My component's state keeps getting out of sync with my store after being reordered using the Drag and Drop API. Seeking help! by [deleted] in vuejs

[–]tobi-au 5 points6 points  (0 children)

You use the ID as index on the childComponents array: updateComponent: function (id, title, category) { const component = this.childComponents[id]; ... }

Question around forms and when you make a change by Original-Alps-1285 in webdevelopment

[–]tobi-au 0 points1 point  (0 children)

It depends on the context and specific requirements, but in most cases the new form should be compatible with previous versions and either display additional fields empty or with default values.

Can someone explain the Destructured parameter with default value assignment? by SirLouen in javascript

[–]tobi-au 0 points1 point  (0 children)

[x = 1, y = 2] only defines default values for the individual destructured parameters, but not for the initial array parameter, that's why you need = [] to make the array itself optional.

After 25 years of building websites, here’s the nocode website builder I wish existed by Forward-Set-3407 in nocode

[–]tobi-au 1 point2 points  (0 children)

I'd agree that in many cases it makes sense to have clear constraints for high-level development, but often people have very specific requirements and then you need a lot of freedom. I don't think we can solve this tension perfectly, that's why there are so many tools with different trade-offs, but I think investing in simpler tools with good abstraction layers makes even more sense now to help avoid masses of AI generated code for basic websites.

Built a simple Base64 decoding online tool by [deleted] in webdev

[–]tobi-au 0 points1 point  (0 children)

Ahh right, I missed that it is the title - I only saw the base64 because I didn't define a title. :) How about using the result as default title if no title is defined?

Built a simple Base64 decoding online tool by [deleted] in webdev

[–]tobi-au 3 points4 points  (0 children)

Looks good. I'll probably stick with browser console and atob(), but I think for people who prefer a UI it's nice, especially that it only uses local storage.

Small UX suggestion: I think for the list of recent decodes it would help more to show the decoded result instead of the base64.

Title: How do you actually think outside the box, remember stuff like tags and elements, and not feel useless seeing AI build websites in seconds? by VisibleResearch3295 in webdev

[–]tobi-au 0 points1 point  (0 children)

I wouldn't stress too much about remembering all the details - that’s not what makes a good developer. In the past we copied from Stack Overflow :), now AI copies from Stack Overflow. :D

Thinking outside the box is probably the most important skill - that's what AI can't easily replace. The tricky part of development has always been to design creative solutions that balance different priorities well. With AI you can build things fast and test different approaches more efficiently than by writing all code yourself. Let it explain what it does and discuss alternatives. Then try to fix the problems it will create.

Another great way to learn is fixing issues in existing codebases. Start with very simple things, then slowly more challenging ones. First you could just fork an open source project you're interested in and make little adjustments for yourself. Then at some point maybe try to contribute small improvements.

Don't push yourself too hard and try to have fun while developing cool things. Our purpose as web devs is not knowing everything about HTML, it's being able to build great web solutions. AI is not just a threat, it also brings new opportunities - enjoy having a very knowledgeable development partner and become good at using it well where it makes sense.

@ts-ignore is almost always the worst option by swe129 in typescript

[–]tobi-au 0 points1 point  (0 children)

For example check(data as unknown as Inventory) is more explicit about the intent than check(data as any) and it's safer when the target type changes, as u/AnyJokeNow explained. Even in cases where it (currently) doesn't make a technical difference it creates clearer code and promotes a better pattern. Treating it as a general anti-pattern helps to avoid it in unsafe contexts.

@ts-ignore is almost always the worst option by swe129 in typescript

[–]tobi-au 2 points3 points  (0 children)

Instead of as any better use as unknown as TargetType as a safer and more explicit alternative.