A type argument supplies a specific type for a generic type parameter. Write it in angle brackets when creating an object or calling a generic method. In `new DataCollection<Person>(people)`, `Person` replaces the class’s `T`: the constructor and `add` accept `Person` objects, and `getItem` returns a `Person`. The resulting object has type `DataCollection<Person>`. section 12.3.1
Restrict a JavaScript Map
In `src/todoCollection.ts`, `private itemMap = new Map<number, TodoItem>();` specifies number keys and `TodoItem` values. JavaScript’s Map can otherwise hold mixed keys and values; these arguments let the TypeScript compiler reject incompatible uses. The value type also carries through `values()` into an array of to-do items. section 2.2.6
Choose or infer arguments according to how the generic is used:
- Separate instances can use different arguments: `DataCollection<Person>` and `DataCollection<Product>` retain their respective item types. section 12.3.2
- You can omit arguments when constructor or method inputs let the compiler infer them. Check the inferred type—initializing with the wrong types can give an unintended result. With declaration output enabled, `dist/index.d.ts` shows inferred types. section 12.3.5
- A static method does not use its class’s instance type argument. It can define its own: `DataCollection.reverse<City>(cities)`. section 12.3.8
Arguments must also satisfy any constraint on a type parameter. A subclass may pass its parameter to a generic superclass, restrict it further, or fix the superclass’s parameter to one type. A subclass whose superclass type is fixed this way takes no type argument of its own. section 12.5 section 12.3.6
Type argument versus function argument
In `getValue<Product, "name">(p, "name")`, the first `"name"` is a literal type argument checked against `keyof Product`. The second is the string value passed to the function at runtime. The compiler can also infer the type arguments from a call such as `getValue(p, "price")`. section 13.4.2
Libraries use the same TypeScript feature. `LowSync<schemaType>` describes the structure expected from a JSON-backed database. In an Angular data source, `http.get<Product[]>(url)` specifies the expected result type, which flows into an `Observable<Product[]>`. Specify a type that corresponds to the server’s data; the type argument is not Angular-specific behavior. section 2.5 section 18.3.2




