[Proposal]: Target-typed inference for constructor calls
- Dominant language
- C#
- Stars
- 12.7k
- Forks
- 1.1k
- Avg merge
- 11h 1m
- Merged PRs (30d)
- 3
Description
# Target-typed inference for constructor calls
* Specification: https://github.com/dotnet/csharplang/blob/main/proposals/inference-for-constructor-calls.md
* Discussion: https://github.com/dotnet/csharplang/discussions/9629
## Summary
[summary]: #summary
Generic type inference is extended to 'new' expressions, which may infer type arguments for the newly created class or struct, including [from a target type](target-typed-generic-type-inference) if present. For instance, given:
```csharp
public class MyCollection : IEnumerable
{
public MyCollection() { ... }
...
}
```
We would allow the constructor to be called without a type argument when it can be inferred from arguments or (in this case) a target type:
```csharp
IEnumerable c = new MyCollection(); // 'T' = 'string' inferred from target type
```
## Design meetings
* https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-08-18.md#type-inference
* https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-08-20.md#target-type-inference-improvements
* https://github.com/dotnet/csharplang/blob/main/meetings/2026/LDM-2026-08-19.md#type-parameter-inference-for-constructor-calls
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.