对于Typescriptreact-找不到模块“react-materialize”的声明文件。'path/to/module-name.js'隐含任何类型感兴趣的读者,本文将会是一篇不错的选择,并为
对于Typescript react - 找不到模块“react-materialize”的声明文件。'path/to/module-name.js' 隐含任何类型感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于Dockerize React 使用 Typescript、ReactRouter 和 nginx 作为反向代理、Flink 数据类型和序列化机制简介/TypeInformation createSerializer TypeSerializer、React js Typescript Argument'string'类型不能分配给'SetStateAction
- Typescript react - 找不到模块“react-materialize”的声明文件。'path/to/module-name.js' 隐含任何类型
- Dockerize React 使用 Typescript、ReactRouter 和 nginx 作为反向代理
- Flink 数据类型和序列化机制简介/TypeInformation createSerializer TypeSerializer
- React js Typescript Argument'string'类型不能分配给'SetStateAction
'类型的参数 - React Native / Typescript-错误模块“ react-native”没有导出的成员“ Pressable” .ts(2305)
Typescript react - 找不到模块“react-materialize”的声明文件。'path/to/module-name.js' 隐含任何类型
我正在尝试从 react-materialize 导入组件为-
import {Navbar, NavItem} from ''react-materialize'';
但是当 webpack 编译我的.tsx
时候,它会抛出一个错误,因为 -
ERROR in ./src/common/navbar.tsx(3,31): error TS7016: Could not find a declaration file for module ''react-materialize''. ''D:\Private\Works\Typescript\QuickReact\node_modules\react-materialize\lib\index.js'' implicitly has an ''any'' type.
有什么解决办法吗?我不确定如何解决此导入语句以与ts-loader
webpack 一起使用。
index.js
react-materialize 的样子是这样的。但是如何解决这个问题,以便在我自己的文件中导入模块?
https://github.com/react-materialize/react-
materialize/blob/master/src/index.js
答案1
小编典典对于那些想知道我是如何克服这一点的人。我做了一些 hack 的东西。
在我的项目中,我创建了一个名为@types
并将其添加到 tsconfig.json 的文件夹,以便从中查找所有需要的类型。所以它看起来有点像这样 -
"typeRoots": [ "../node_modules/@types", "../@types"]
在其中我创建了一个名为alltypes.d.ts
. 从中找出未知的类型。所以对我来说,这些是未知类型,我在那里添加了它。
declare module ''react-materialize'';declare module ''react-router'';declare module ''flux'';
所以现在打字稿不再抱怨找不到类型了。:) 现在赢得胜利 :)
Dockerize React 使用 Typescript、ReactRouter 和 nginx 作为反向代理
如何解决Dockerize React 使用 Typescript、ReactRouter 和 nginx 作为反向代理?
我目前正在通过 Docker 和 Docker Compose 构建架构。 在本例中,我有两个具有以下设置的应用:
我希望可以通过以下网址访问这些应用: app1 前端:http://localhost/app1 app1 后端:http://localhost/app1/backend
app2 前端 http://localhost/app2 app2 后端 http://localhost/app2/backend
在应用程序的前端,我将 React 与 Typescript 和 ReactRouter 结合使用。 在后端,我使用 .NET 5 Core。它们分别在端口 5000 和 5001 下运行。
此外还使用了 Nginx 形式的反向代理。
只要根 URL 在 ReactRouter 中寻址,这就可以正常工作。 URL 中的不同路径导致来自 Nginx 的 HTTP 404。
App1 中的 ReactRouter:
import ''./App.css'';
import {
browserRouter as Router,Switch,Route,Link
} from "react-router-dom";
import Home from ''./components/home/Home'';
import WeatherForeCastList from ''./components/weatherForeCastList/WeatherForeCastList'';
function App() {
return (
<div className="App">
<Router>
<Switch>
<Route path="/b">
<WeatherForeCastList />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</Router>
</div>
);
}
export default App;
Nginx 配置:
# auto detects a good number of processes to run
worker_processes auto;
#Provides the configuration file context in which the directives that affect connection processing are specified.
events {
# Sets the maximum number of simultaneous connections that can be opened by a worker process.
worker_connections 8000;
# Tells the worker to accept multiple connections at a time
multi_accept on;
}
http {
# what times to include
include /etc/Nginx/mime.types;
# what is the default one
default_type application/octet-stream;
# Sets the path,format,and configuration for a buffered log write
log_format compression ''$remote_addr - $remote_user [$time_local] ''
''"$request" $status $upstream_addr ''
''"$http_referer" "$http_user_agent"'';
upstream app1_backend {
# Must be service name of docker compose file
server app1-backend:5000;
}
upstream app2_backend {
# Must be service name of docker compose file
server app2-backend:5000;
}
server {
# listen on port 80
listen 80;
# save logs here
access_log /var/log/Nginx/access.log compression;
# where the root here
root /usr/share/Nginx/html;
# what file to server as index
index index.html index.htm;
location /app1/backend/ {
rewrite /app1/backend/(.*) /$1 break;
proxy_pass http://app1_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /app2/backend/ {
rewrite /app2/backend/(.*) /$1 break;
proxy_pass http://app2_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
# First attempt to serve request as file,then
# as directory,then fall back to redirecting to index.html
try_files $uri $uri/ /index.html;
}
}
}
Docker-File app1 前端:
FROM node:12.18-alpine AS builder
ENV NODE_ENV=production
workdir /app1/frontend
copY . .
RUN rm -rf node_modules
RUN npm install --production --silent
RUN rm -rf build
RUN PUBLIC_URL=http://localhost/app1 npm run build --loglevel verbose
Docker-File app1 后端:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
workdir /app1/backend
#EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info,please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app1
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
workdir /src
copY ["backend.csproj","."]
RUN dotnet restore "backend.csproj"
copY . .
RUN dotnet build "backend.csproj" -c Release -o /app1/backend/build
FROM build AS publish
RUN dotnet publish "backend.csproj" -c Release -o /app1/backend/publish
FROM base AS final
workdir /app1/backend
copY --from=publish /app1/backend/publish .
ENTRYPOINT ["dotnet","backend.dll"]
Docker Compose:
version: ''3.4''
services:
postgres:
build:
context: ./db
dockerfile: ./Dockerfile
hostname: postgres
ports:
- 5432:5432
environment:
- POSTGRES_MULTIPLE_DATABASES=app1,app2
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- postgres-data:/var/lib/postgresql/data
restart: unless-stopped
pgadmin:
image: dpage/pgadmin4
ports:
- 5555:80
environment:
PGADMIN_DEFAULT_EMAIL: postgres@postgres.de
PGADMIN_DEFAULT_PASSWORD: postgres
restart: unless-stopped
volumes:
- pgadmin-data:/var/lib/pgadmin
depends_on:
- postgres
app1-backend:
image: app1-backend
build:
context: ./app1/backend
dockerfile: ./Dockerfile
depends_on:
- postgres
app1-frontend:
image: app1-frontend
build:
context: ./app1/frontend
dockerfile: ./Dockerfile
environment:
NODE_ENV: production
PUBLIC_URL: http://localhost/app1
stdin_open: true
volumes:
- app1-frontend-build:/app1/frontend/build
depends_on:
- app1-backend
app2-backend:
image: app2-backend
build:
context: ./app2/backend
dockerfile: ./Dockerfile
depends_on:
- postgres
app2-frontend:
image: app2-frontend
build:
context: ./app2/frontend
dockerfile: ./Dockerfile
environment:
NODE_ENV: production
PUBLIC_URL: http://localhost/app2
stdin_open: true
volumes:
- app2-frontend-build:/app2/frontend/build
depends_on:
- app2-backend
router:
image: router
build:
context: ./router
dockerfile: ./Dockerfile
ports:
- 80:80
volumes:
- app1-frontend-build:/usr/share/Nginx/html/app1
- app2-frontend-build:/usr/share/Nginx/html/app2
depends_on:
- app1-frontend
- app2-frontend
volumes:
postgres-data:
pgadmin-data:
app1-frontend-build:
app2-frontend-build:
这里有人知道为什么 URL 是: http://localhost/app1/ 有效
但是网址: http://localhost/app1/b 没有(来自 Nginx 的 404)?
感谢您的努力,如果您需要更多信息,请告诉我!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Flink 数据类型和序列化机制简介/TypeInformation createSerializer TypeSerializer
Flink自己定义了一套数据类型,对应Java中的基本类型、集合、POJO等,数据类型都是TypeInformation的子类,并且在每个子类中都重写了createSerializer方法来创建自己类型的TypeSerializer,然后使用TypeSerializer来实现序列化和反序列化。
如果Flink无法识别或推断类型,则使用Kryo序列化反序列化。如果Kryo无法实现序列化反序列化,可以使用强制avro或者为 Kryo 增加自定义的 Serializer 以增强 Kryo 的功能,实现序列化反序列化。
---------------------
Flink 的分布在不同节点上的 Task 的数据传输必须经过序列化/反序列化,因此序列化/反序列化也是影响 Flink 性能的一个重要因素。Flink 自有一套类型体系,即 Flink 有自己的类型描述类(TypeInformation)。Flink 希望能够掌握尽可能多的进出 operator 的数据类型信息,并使用 TypeInformation 来描述,这样做主要有以下 2 个原因:
- 类型信息知道的越多,Flink 可以选取更好的序列化方式,并使得 Flink 对内存的使用更加高效;
- TypeInformation 内部封装了自己的序列化器,可通过 createSerializer() 获取,这样可以让用户不再操心序列化框架的使用(例如如何将他们自定义的类型注册到序列化框架中,尽管用户的定制化和注册可以提高性能)。
总体上来说,Flink 推荐我们在 operator 间传递的数据是 POJOs 类型,对于 POJOs 类型,Flink 默认会使用 Flink 自身的 PojoSerializer 进行序列化,而对于 Flink 无法自己描述或推断的数据类型,Flink 会将其识别为 GenericType,并使用 Kryo 进行序列化。Flink 在处理 POJOs 时更高效,此外 POJOs 类型会使得 stream 的 grouping/joining/aggregating 等操作变得简单,因为可以使用如: dataSet.keyBy("username") 这样的方式直接操作数据流中的数据字段。
除此之外,我们还可以做进一步的优化:
- 显示调用 returns 方法,从而触发 Flink 的 Type Hint:
dataStream.flatMap(new MyOperator()).returns(MyClass.class)
returns 方法最终会调用 TypeExtractor.createTypeInfo(typeClass) ,用以构建我们自定义的类型的 TypeInformation。createTypeInfo 方法在构建 TypeInformation 时,如果我们的类型满足 POJOs 的规则或 Flink 中其他的基本类型的规则,会尽可能的将我们的类型“翻译”成 Flink 熟知的类型如 POJOs 类型或其他基本类型,便于 Flink 自行使用更高效的序列化方式。