google / google/styleguide

jsguide: Explain more - Infer Templatized type/ template parameter, but not its parameters

Open
#586 0 comments 0 reactions 0 assignees View on GitHub
lang:js
Dominant language
HTML
Stars
39.6k
Forks
12.9k
Avg merge
42m
Merged PRs (30d)
15

Description

https://google.github.io/styleguide/jsguide.html#features-declare-types-as-needed

Tip: There are many cases where the compiler can infer a templatized type but not its parameters. This is particularly the case when the initializing literal or constructor call does not include any values of the template parameter type (e.g., empty arrays, objects, Maps, or Sets), or if the variable is modified in a closure. Local variable type annotations are particularly helpful in these cases since otherwise the compiler will infer the template parameter as unknown.

- Please explain this tip in detail with an example:
- "Infer Templatized type/ template parameter, but not its parameters"

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.