interface TypeMap {
"string": string;
"number": number;
"bool": Boolean;
}
export declare function create<T extends keyof TypeMap>(
tagName: T,
): TypeMap[T];
// Usage
const t : string = create("string");
const t2 : string = create("number"); // Error because number is not assignable to string
translates into something like
[<Erase>]
type Exports =
[<Import("create", "module")>]
static member create (tagName: Exports.create.T) : obj = nativeOnly
module Exports =
module create =
[<RequireQualifiedAccess>]
[<StringEnum(CaseRules.None)>]
type T =
| [<CompiledName("string")>] string
| [<CompiledName("number")>] number
| [<CompiledName("bool")>] bool
[<AllowNullLiteral>]
[<Interface>]
type TypeMap =
abstract member string: string with get, set
abstract member number: float with get, set
abstract member bool: bool with get, set
TypeScript documentation:
translates into something like
Example of npm package using this features:
Leaflet