【发布时间】:2021-05-15 23:01:49
【问题描述】:
我有两个 TypeScript 文件。
常量.ts:
export const defaultProps = {
name: 'Node'
};
MyComponent.tsx:
import * as React from 'react';
import {defaultProps} from './const';
interface MyCompProps {
name: string;
}
export class MyComp extends React.Component<MyCompProps> {
static defaultProps = defaultProps;
constructor(props: MyCompProps) {
super(props);
}
render() {
const {name} = this.props;
return <div>{name}</div>;
}
}
我正在使用 TypeScript 编译器 API 来解析这些文件。我对这条线感兴趣:
static defaultProps = defaultProps;
在右侧我有带有kind=265(ImportSpecifier)的节点。如何从具有对象文字值的节点中获取?使用方法checker.getSymbolAtLocation(node) 返回undefined。
【问题讨论】:
-
如何使用编译器 API?只是好奇。很有趣的话题
标签: typescript typescript-compiler-api