question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow specifying only a subset of generic type parameters explicitly instead of all vs none

See original GitHub issue

TypeScript Version: 2.3.0 https://www.typescriptlang.org/play/ Code

class Greeter<T, S> {
    greeting: T;
    constructor(message: T, message2: S) {
        this.greeting = message;
    }

}

let greeter = new Greeter<string>("Hello", "world");

Expected behavior:

The compiler should infer S to be string.

Actual behavior: Error:

Supplied parameters do not match any signature of call target.

The compiler expects either all generic parameters to be specified explicitly or none at all.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:77
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

17reactions
joonhochocommented, Jul 30, 2018

I too am currently using currying as well as workaround, but it feels too hacky to me. I wish this can be resolved.

11reactions
alisd23commented, Mar 11, 2018

For anyone else wondering about a workaround, as @alshain said you can use currying. The workaround for the above example would be:

function test<S>() {
  return function<T extends keyof S>(tValue: T): any {
    return null;
  };
}

test<SomeType>()('some-key');
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How to refactor a method to a generic one accepting ...
So it should be able to accept only those types extending my MyParentEntity but able to specify another type ( List<MyOtherEntity> , List<MyAwesomeEntity>...
Read more >
Understanding TypeScript Generics - Smashing Magazine
An introduction to the utilization of Generics in TypeScript with examples grounded in real-world use cases, such as collections, ...
Read more >
Constraints on type parameters - C# Programming Guide
The type argument must be a reference type, either nullable or non-nullable. This constraint applies also to any class, interface, delegate, ...
Read more >
Built-in Types — Python 3.11.1 documentation
The methods that add, subtract, or rearrange their members in place, and don't return a specific item, never return the collection instance itself...
Read more >
Google C++ Style Guide
Consistency also allows for automation: tools that format your code or adjust ... source type as its only argument (or only argument with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found