Closed
Description
TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms: named generic type parameters / arguments
Code
interface UserInfo { }
var usersMap: Map<sessionId: string, info: UserInfo>;
Expected behavior:
No error, Map<sessionId: string, info: UserInfo>
should be equivalent to Map<string, UserInfo>
.
Actual behavior:
Syntax error: Generic type 'Map<K, V>' requires 2 type argument(s).
Rationale:
Without a name, it is not often immediately clear what a type argument really mean. Take Map<string, UserInfo>
as an example, is the first argument a sessionId
, a userId
or something else? In contrast, Map<sessionId: string, info: UserInfo>
or Map<sessionId: string, UserInfo>
is very clear.
The name of a type argument doesn't affect the actual type, just like the name of argument of a function type.