小编kan*_*256的帖子

找不到模块:错误:将打字稿添加到 CRA 应用程序时无法解析打字稿文件

我正在尝试添加typescript到我的项目中并使用打字稿编写新组件。我按照文档进行操作,但出现此错误:
can't resolve [the typescript file]

即使是新create-react-app项目也会发生这种情况。
根据CRA 文档添加typescript到现有的 Create React App 项目,首先,我们必须typescript安装type definition files

npm install --save typescript @types/node @types/react @types/react-dom @types/jest
Run Code Online (Sandbox Code Playgroud)

快完成了!
将文件重命名js/jsxtsx并重新启动您的开发服务器!

为简单起见,我创建一个typescript名为test.tsx包含该Test组件的文件:

export default function Test(){
    return (
        <div>this is test to see typescirpt</div>
    )
}
Run Code Online (Sandbox Code Playgroud)

并将其导入main.js并渲染:

import Test from "./test";

function App() {
  return (
    <div className="App">
      <Test />
    </div>
  ); …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs webpack create-react-app

16
推荐指数
2
解决办法
4万
查看次数

在带有标记文本的 altair 中对条形图进行排序的问题

chart_df= alt.Chart(df).mark_bar().encode(
    x = 'value',
    y = alt.Y('name', sort='-x'),
    color = 'variable'
)
Run Code Online (Sandbox Code Playgroud)

为了将每个条的值添加为文本,我使用了波纹管代码,但我丢失了排序的条。

chart_df_text = chart_df.mark_text().encode(
    x = 'text_margin_from_bar:Q',
    text = 'human_readable_value:Q',
).transform_calculate(
    human_readable_value = expr.toString(expr.floor(datum.value/10**7)),
    text_margin_from_bar = datum.value + (datum.value/expr.abs(datum.value))*1000000000
    # i have negetive and positive numbers, so for have a space between number and bar, i do this
)
Run Code Online (Sandbox Code Playgroud)

添加

y = alt.Y('name', sort='-x'),
Run Code Online (Sandbox Code Playgroud)

到 chart_df_text 但我仍然有问题。我读了另一个有我问题的问题,说问题是 Altair 的版本,但我在最后一个。

python altair

2
推荐指数
1
解决办法
360
查看次数

标签 统计

altair ×1

create-react-app ×1

python ×1

reactjs ×1

typescript ×1

webpack ×1