Skip to content

Commit

Permalink
fix(taro.components): fix Taro.FC typings and others, close #4987
Browse files Browse the repository at this point in the history
  • Loading branch information
Garfield550 committed Dec 2, 2019
1 parent f681da1 commit 57c3346
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions packages/taro/types/taro.component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,17 @@ declare namespace Taro {
onResize?(obj: any): void
}

interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> {
$scope?: any
}

interface ComponentOptions {
addGlobalClass?: boolean
}

interface FunctionComponent<P = {}> {
(props: Readonly<P>): JSX.Element
defaultProps?: Partial<P>
config?: Config
options?: ComponentOptions
}

type FC<P = {}> = FunctionComponent<P>

interface StatelessFunctionComponent {
(): JSX.Element
}

type SFC = StatelessFunctionComponent

interface ComponentClass<P = {}, S = any> extends StaticLifecycle<P, S> {
new (...args: any[]): Component<P, {}>
propTypes?: any
propTypes?: any // TODO: Use prop-types type definition.
defaultProps?: Partial<P>
displayName?: string
}

interface ComponentOptions {
addGlobalClass?: boolean
}

interface RouterInfo {
/**
* 在跳转成功的目标页的生命周期方法里通过 `this.$router.params` 获取到传入的参数
Expand Down Expand Up @@ -106,8 +83,17 @@ declare namespace Taro {
}
}

interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> {
$scope?: any
}

class Component<P, S> {
constructor(props?: P, context?: any)
constructor(props: Readonly<P>)
/**
* @deprecated
* @see https://reactjs.org/docs/legacy-context.html
*/
constructor(props: P, context?: any)

config?: Config

Expand Down Expand Up @@ -135,16 +121,34 @@ declare namespace Taro {

forceUpdate(callBack?: () => any): void

render(): any
render(): React.ReactNode

props: Readonly<P> & Readonly<{ children?: any }>
readonly props: Readonly<P> & Readonly<{ children?: React.ReactNode }>
state: Readonly<S>
context: any
refs: {
[key: string]: any
}
}

type PropsWithChildren<P> = P & { children?: React.ReactNode };

interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): React.ReactElement | null
propTypes?: any // TODO: Use prop-types type definition.
defaultProps?: Partial<P>
config?: Config
options?: ComponentOptions
}

type FC<P = {}> = FunctionComponent<P>

interface StatelessFunctionComponent {
(): JSX.Element
}

type SFC = StatelessFunctionComponent

class PureComponent<P = {}, S = {}> extends Component<P, S> {}

function memo<P = {}>(
Expand Down

0 comments on commit 57c3346

Please sign in to comment.