Repository: TypeScript
Issue: Add getMappedTypeParameters to TypeChecker
Labels: Suggestion,In Discussion

## Search Terms
TypeMapper, mapper, mapper1, mapper2

## Suggestion
To help transformer developers: Add a helper on `TypeChecker` to provide (and expose) the inferred (mapped) types of a source function call. i.e. 

given the source:

```ts 
function foo<C>(ctor: C)...

foo(Bar);
```

provide transformer developers a method (on ```ts.TypeChecker```)

```ts 
getMappedTypeParameters(node: ts.CallExpression): ts.Type[]
```
so they can get the inferred TypeParameter nodes for a given source call-expression. By adding a helper method, it does not expose the internal mapping, limits the required maintenance if the internal mapping is ever changed, yet allows developers access to the inference information. 

## Use Cases

During AST code transform, the compiler has already inferred the types passed to source functions, without them being explicitly defined as a type parameter in the call.  The current `Signature` (```typeChecker.getResolvedSignature(node)```) does not expose these inferred types and the ```signature.typeParameters`` remains `undefined`

For transformers that require this information, the current work around is use the internal "mapper" field on `Signature`. This mapper field changed in ts 3.9 and potentially could change again. Exposing an ability to access this mapping via the TypeChecker should help reduce breakage and limit maintainance required by the TypeScript Team to expose and execute the mapping. 

## Examples

In my [DI transformer](https://github.com/pigly-di/pigly), I attempt to infer Type parameters and use them to manipulate the compiled output to configure the DI Container. For example; the source code: 

```ts
function main() {
  let kernel = new Kernel();

  kernel.bind(toSelf(Bar));  
  kernel.bind(toSelf(Foo));
}```

is transpiled to: 

```js
function main() {
    let kernel = new pigly_1.Kernel();
    kernel.bind(Symbol.for("Bar"), pigly_1.toSelf(Bar));
    kernel.bind(Symbol.for("Foo"), pigly_1.toSelf(Foo, ctx => ctx.resolve({ service: Symbol.for("Bar"), name: "bar" }).first()));
}
```

As relevant to this proposal, my transpiler needs to be able to infer the TypeParameter of `.bind<T>` so that it can emit a symbol for it into the runtime code. 

My Current work around to discover the inferred mappings is here: 
https://github.com/pigly-di/pigly/blob/develop/packages/pigly-transformer/src/index.ts#L284-L331

Admittedly this is a very niche proposal (if allowed I'd happily do a PR to add it and do the tests) - but at least one other developer had trouble with this: https://stackoverflow.com/questions/48886508/typechecker-api-how-do-i-find-inferred-type-arguments-to-a-function

## Checklist

My suggestion meets these guidelines:

* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [x] This wouldn't change the runtime behavior of existing JavaScript code
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).