Learning TypeScript by Josh Goldberg

Learning TypeScript by Josh Goldberg

Author:Josh Goldberg [Josh Goldberg]
Language: eng
Format: epub
Publisher: O'Reilly Media, Inc.
Published: 2022-06-10T00:00:00+00:00


Explicit Generic Class Types

Instantiating generic classes goes by the same type arguments inference rules as calling generic functions. If the type argument can be inferred from the type of a parameter to the class constructor, such as the new Secret(12345, "luggage") earlier, TypeScript will use the inferred type. Otherwise, if a class type argument can’t be inferred from the arguments passed to its constructor, the type argument will default to unknown.

This CurriedCallback class declares a constructor that takes in a generic function. If the generic function has a known type—such as from an explicit type argument type annotation—then the class instance’s Input type argument can be informed by it. Otherwise, the class instance’s Input type argument will default to unknown:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.