【发布时间】:2017-05-01 23:34:02
【问题描述】:
我正在尝试为 docuri 定义
export type URI<K extends RouteParams> = string;
export interface RouteParams {
[key: string]: (string | number | boolean)
}
export interface Document {
[key: string]: (string | number | boolean)
}
/**
* Create a URI from a document properties
* @param the props to build the URI from
* @return the URI
*/
export type RouteCreator<K extends RouteParams> = (props: K) => string;
/**
* Parses a URI and returns the props
* @param uri the URI to parse
* @return the params parsed from URI
*/
export type RouteParser<K extends RouteParams> = (uri: string) => K;
export type Route<T extends RouteParams> = RouteParser<T> | RouteCreator<T>;
/**
* Creates a Route which is a function that either parse or stringify object/string
* @param route the route uri
* @return the Route
*/
export type RouteFactory<K extends RouteParams> = (route: string) => Route<K>;
export interface DocURI<K extends RouteParams> {
route: RouteFactory<K>;
}
然后使用它:
import {DocURI, Document, RouteParams, URI, RouteFactory} from './Definitions';
const docuri = require('docuri');
function getRoute <T extends Document> (): DocURI<T> {
return (docuri as DocURI<T>);
}
...
const artistURI = getRoute<ArtistParams>().route('artist/name');
const parsed = artistURI(album.artist); // Cannot invoke an expression whose type lacks a call signature. Type 'Route<ArtistParams>' has no compatible call signatures.
我在最后一行:
Cannot invoke an expression whose type lacks a call signature. Type 'Route<ArtistParams>' has no compatible call signatures.
我做错了什么?
【问题讨论】:
标签: typescript