Skip to content

Optional Generics? #1387

Open
Open
@esDotDev

Description

@esDotDev

A problem with the current Generic implementation, is anytime you want to specify one type, you need to declare them all. This can lead to excessive typing and obfuscation of intent.

Sometimes I find I need to add specificity to just one of the types, it would be nice if this could be expressed as:

useProp<_, _, float>();

Instead of the current:

useProp<KnownType1, KnownType2, float>();

I've had to do this when there is some ambiguity to the inferred types, and you need to add a little bit of an extra hint to the compiler.

An example of such a case is like this:

class Thing<T> {}
void useThing<T>(Thing<T> t, T value) {}

void fn() {
  //Thing t is declared to be of type bool
  Thing<bool> t = Thing<bool>();
  // But somehow, this is not an error...
  useThing(Thing<bool>(), 1); // No error here :(
  // We need to give it another hint; 
  useThing<bool>(Thing<bool>(), 1); //Now we have an error :) 
}

If Thing was instead Thing<T1,T2,T3> this gets pretty annoying. The fact it falls to dynamic here is also annoying, but I guess that is a separate issue, or maybe a linter rule I'm missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions