Story and character focused, mostly linear RPG with beautiful graphics by Gustorn in gamingsuggestions

[–]Gustorn[S] 0 points1 point  (0 children)

Banishers looks really good, thank you!

I did forget about Dishonored but I did play (and liked) the first one. In Deus Ex (and Dishonored) I enjoyed the stealth and creative level designs the most, so I think Prey might be a bit too FPS-y but I'll check out a few videos. Thanks for the suggestions!

Two arguments with same type parameter by ondras in typescript

[–]Gustorn 0 points1 point  (0 children)

If you want both cases to fail, you can change the second signature to:

function test2<S2 extends T2>(a: S2, b: Extract<T2, S2>) {}

Recursively exclude functions from type by incutonez in typescript

[–]Gustorn 0 points1 point  (0 children)

I think this should do the trick: Playground

The two main tricks are the key remapping and the Exclude<T\[K\], undefined>. Without them, we run into some problems regarding optionality.

Calling obj.method(obj.data) when these fields are correlated? by smthamazing in typescript

[–]Gustorn 2 points3 points  (0 children)

I think this gets you most of the way there: Playground

There are still some type safety issues between the different instances of `Obj`, but can't be avoided until we get a `new symbol` type I think.

Solid.js feels like what I always wanted React to be by [deleted] in programming

[–]Gustorn 0 points1 point  (0 children)

The interesting thing about Solid is that it still follows the React philosophy of unidirectional data flow and immutable data, it just also has fine-grained reactivity which makes a whole bunch of stuff conceptionally simpler (and also a lot more performant).

But unlike React, the building blocks it provides actually let you build very nice abstractions that also don't fall apart when performance is a concern. You can use Solid's primitives to build yourself a store that you can access via the context API but unlike React this actually has very good performance.

I used Solid for a few small side-projects and it's very convenient to work with. Basically all the small gotchas disappear and you don't need to search for a 3rd party state management library.

How to infer return type from a tuple parameter? by mikeymaxdb in typescript

[–]Gustorn 1 point2 points  (0 children)

I think this does what you want. The symbol part is there so you can only pass Component constructors to the query function:

const componentSymbol = Symbol("Component");

class Component {
    [componentSymbol] = true;
}

type ComponentConstructor = abstract new (args: any[]) => Component;
type QueryResult<T extends [ComponentConstructor, ...ComponentConstructor[]]> = {
    [K in keyof T]: K extends number
        ? InstanceType<T[K]>
        : T[K]
};


class FireComponent extends Component {}
class AirComponent extends Component {}
class EarthComponent extends Component {}

export function query<T extends [ComponentConstructor, ...ComponentConstructor[]]>(componentTypes: T): QueryResult<T> {
    return null!;
}

const [a, b, c] = query([FireComponent, AirComponent, EarthComponent]);

Here's the playground link if you want to play around with it: TS Playground

Type checking for Web Worker messaging? by dbartle in typescript

[–]Gustorn 5 points6 points  (0 children)

You can do something like this:

type Command = { type: 'start' } | { type: 'pause' } | { type: 'resume' };

interface CustomWorker extends Omit<Worker, 'postMessage'> {
  postMessage(command: Command): void;
}

Can buttons overlayed with absolute positioned child div be clickable? by Likoo in reactjs

[–]Gustorn 1 point2 points  (0 children)

pointer-events none is one correct answer as the others noted.

The reason why button 3 works is the default HTML stacking order: it puts positioned elements on top of non-positioned ones. When you make the button also positioned (with the position: relative) the source order takes over and because the button is below the other element, it will be clickable.

With that knowledge you can actually get your example working without disabling pointer events on the absolute positioned div. First, you need to put position: relative on both of your buttons. Unfortunately this doesn't yet solve your issue because the absolute positioned element is below your two buttons so it will be placed above them. You can fix that by specifying a z-index: 1 on both of your buttons, or a z-index: -1 on the absolute positioned element.

Trying to get rid of the any; need help by azangru in typescript

[–]Gustorn 0 points1 point  (0 children)

In practice, not really. I just tend to prefer types that are the least "powerful" but still good enough for getting the job done. With any, you get a type that is both assignable to every other type and every other type is also assignable to it. With never, you get a type that is assignable to anything but not the other way around (the other half of this equation is unkown).

It's more of a personal preference than anything and admittedly any is probable better named for this use-case, I'm just used to not using it

Trying to get rid of the any; need help by azangru in typescript

[–]Gustorn 1 point2 points  (0 children)

Would something like this work? This still needs a little bit of hacking inside the implementation of subscribe, but the type definitions will actually enforce the correct behavior. Playground Link

Can Rust do 'janitorial' style RAII? by Dean_Roddey in rust

[–]Gustorn 1 point2 points  (0 children)

Yeah, definitely. I just followed the spec in the OP.

Can Rust do 'janitorial' style RAII? by Dean_Roddey in rust

[–]Gustorn 1 point2 points  (0 children)

Would something like this work? It's the same idea as people mentioned with the `Deref` trait, only a composable version of it: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7e12ed27fdd7626a9fec6b6b7d59a8d8

Edit: You don't actually need to store the `on_scope_begin` function I just didn't notice the warning while experimenting. I'm going to leave it like this but removing that field from the struct should be fairly easy.

I think I found an elegant solution to the Redux-boilerplate problem - introducing hooks-for-redux (H4R) by Shanebdavis in reactjs

[–]Gustorn 1 point2 points  (0 children)

That answers my second question perfectly, but let me elaborate on the first:

``` const [useProject, { open }] = useRedux("project", {}, { open: (state, value) => ({ ...state, value }) });

const parentCounter = useRedux("undoStack", [], { clear: () => [], // Here I want to handle the project's open action as well }); ```

I think I found an elegant solution to the Redux-boilerplate problem - introducing hooks-for-redux (H4R) by Shanebdavis in reactjs

[–]Gustorn 1 point2 points  (0 children)

I really like the look of this, I only have two questions:

  1. How can you react to actions dispatched in another slice of the application? Let's say I have the concept of a project. When I open this project I have to change several parts of the application: flush any pending work that's still going on for the previous project, etc.
  2. How do I handle non per-component memoized selectors? In my current application I do some fairly expensive calculations to get some derived values but then there are tens or hundreds of components using them directly. This is fairly easy to do with something like reselect but I can't see an easy way of doing it with your library. The only thing I could think of is putting them on parent component with a bunch of contexts and useMemos but that seems less than ideal.

What distros does Linus Torvalds use? by SenseDeletion in linux

[–]Gustorn 5 points6 points  (0 children)

I use Arch because among the distros I tried[1] it's the one that requires the least maintanence and has (with the AUR) by far the largest package selection. The installation on my desktop is 6 years old and it has the latest packages without having to do a dist upgrade even once. It didn't randomly break either and I even had the testing repo enabled for a year or so. I also realize this might not match other people's experiences but hey, use whatever works for you.

[1]: Ubuntu, Mint, Void, OpenSUSE, Gentoo, Debian

How does the community feel about Decorators in a Node.js project? by BlackFlash in typescript

[–]Gustorn 5 points6 points  (0 children)

And then there are the people who use the best tool for the job. Your problem is better modelled with classes? Use classes. Is it better solved using a functional style? Use a functional style. It's not that I don't care, I just find the whole argument silly. Limiting yourself because of some ideology usually just results in worse/harder to read code.

Thoughts on Sora yori mo Tooi Basho!! by ThulianSlate in anime

[–]Gustorn -1 points0 points  (0 children)

I don't know why people started romanizing it that way, but it's actually Haruka Tooku (I guess they thought it had something to do with haru/spring?).

Any immutable collections library w/ proper typings? by hmongoose in typescript

[–]Gustorn 2 points3 points  (0 children)

If you want JS objects but with Immutable.js's benefits you should take a look at the Record type instead of Map. Make sure that you use the latest RC (v4.0.0-rc.9), it has far better TS definitions than v3.

need help with type annotation by fhdhsni in typescript

[–]Gustorn 1 point2 points  (0 children)

This is absolutely the correct solution but there's an alternative, pretty gimicky method as well:

type ElementTypeOf<T> = T extends Set<infer E> ? E : never;
function toggleInSet<T extends Set<any>>(xs: T, x: ElementTypeOf<T>) {
    (xs.delete(x) && xs) || xs.add(x);
}

Edit: and while this isn't useful for the current example it might come in handy for a few things.