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 ReactDOM from 'react-dom';
import { import {
adapter, adapter,
@ -8,6 +8,7 @@ import {
addonRendererFactory, addonRendererFactory,
tempRendererFactory, tempRendererFactory,
rendererFactory, rendererFactory,
types,
} from '@ali/lowcode-renderer-core'; } from '@ali/lowcode-renderer-core';
import ConfigProvider from '@alifd/next/lib/config-provider'; import ConfigProvider from '@alifd/next/lib/config-provider';
@ -36,8 +37,23 @@ adapter.setConfigProvider(ConfigProvider);
function factory() { function factory() {
const Renderer = rendererFactory(); const Renderer = rendererFactory();
return class ReactRenderer extends Renderer { return class ReactRenderer extends Renderer implements Component {
constructor(props: any, context: any) { 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); super(props, context);
} }

View File

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

View File

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