fix: 修复在 tsx 文件中使用渲染器 ts 报错问题

This commit is contained in:
liujuping.liujupin 2021-08-23 11:20:26 +08:00 committed by lihao.ylh
parent 5fec8f2697
commit 9afa0771d1
3 changed files with 41 additions and 16 deletions

View File

@ -1,4 +1,4 @@
import React, { Component, PureComponent, createElement, createContext, forwardRef } from 'react';
import React, { Component, PureComponent, createElement, createContext, forwardRef, ReactInstance, ContextType } from 'react';
import ReactDOM from 'react-dom';
import {
adapter,
@ -8,6 +8,7 @@ import {
addonRendererFactory,
tempRendererFactory,
rendererFactory,
types,
} from '@ali/lowcode-renderer-core';
import ConfigProvider from '@alifd/next/lib/config-provider';
@ -36,8 +37,23 @@ adapter.setConfigProvider(ConfigProvider);
function factory() {
const Renderer = rendererFactory();
return class ReactRenderer extends Renderer {
constructor(props: any, context: any) {
return class ReactRenderer extends Renderer implements Component {
readonly props: types.IProps;
context: ContextType<any>;
setState: (
state: types.IState,
callback?: () => void,
) => void;
forceUpdate: (callback?: () => void) => void;
refs: {
[key: string]: ReactInstance,
};
constructor(props: types.IProps, context: ContextType<any>) {
super(props, context);
}

View File

@ -5,7 +5,7 @@ import contextFactory from '../context';
import { isFileSchema, goldlog } from '../utils';
import baseRendererFactory from './base';
import divFactory from '../components/Div';
import { IProps } from '../types';
import { IProps, ISchema, IState } from '../types';
export default function rendererFactory() {
const { createElement, Component, PureComponent, findDOMNode } = adapter.getRuntime();
@ -46,12 +46,14 @@ export default function rendererFactory() {
return class Renderer extends Component {
static dislayName = 'renderer';
static defaultProps = {
state: IState = {};
static defaultProps: IProps = {
appHelper: null,
components: {},
designMode: '',
suspended: false,
schema: {},
schema: {} as ISchema,
onCompGetRef: () => { },
onCompGetCtx: () => { },
};

View File

@ -1,15 +1,22 @@
export interface IProps {
appHelper: any;
components: { [key: string]: any };
componentsMap: { [key: string]: any };
designMode: string;
suspended: boolean;
schema: ISchema;
onCompGetRef: (schema: ISchema, ref: any) => void;
onCompGetCtx: (schema: ISchema, ref: any) => void;
customCreateElement: (...args: any) => any;
notFoundComponent: any;
faultComponent: any;
components: { [key: string]: any };
className?: string;
locale?: string;
appHelper?: any;
componentsMap?: { [key: string]: any };
designMode?: string;
suspended?: boolean;
onCompGetRef?: (schema: ISchema, ref: any) => void;
onCompGetCtx?: (schema: ISchema, ref: any) => void;
customCreateElement?: (...args: any) => any;
notFoundComponent?: any;
faultComponent?: any;
}
export interface IState {
engineRenderError?: boolean;
error?: Error
}
export interface IRendererProps {