typescript - Typescript“声明命名空间”、“声明模块”在全局/模块范围内的区别
问题描述
我无法区分declare module "react"
和declare namespace React
在全局/模块范围内的效果。
例如,我有两个文件:
// File A.ts
import * as React from "react";
export const Button: React.FC = () => {
return <button data-test="whatever" />
}
/* File B.ts */
// 1:
declare module "react" {
interface ButtonHTMLAttributes<T> {
"data-test": string;
}
}
// 2:
declare module "react" {
interface ButtonHTMLAttributes<T> {
"data-test": string;
}
}
export {}
// 3:
declare namespace React {
interface ButtonHTMLAttributes<T> {
"data-test": string;
}
}
//4:
declare namespace React {
interface ButtonHTMLAttributes<T> {
"data-test": string;
}
}
export {}
这四个“声明”版本中的每一个都将对文件 A 中的“反应”符号做什么?版本 1 似乎完全覆盖了“反应”。版本 2 和 3 似乎改为“扩展”它。版本 3 似乎没有效果。
谢谢!
解决方案
推荐阅读
- c# - 系统特定的 ListView 列宽更改行为
- android - JSoup web-scraping:如何选择每个值
- amazon-web-services - 编译 NumPy 并上传到 AWS Lambda
- python - How to use string.count command and use a starting point?
- grails - Grails - 与 beforeInsert 和布尔赋值相关的 NullPointerException
- c - 当您将文字字符串作为函数中的参数传递时,C 会添加 '\0' 吗?
- r - 如何将字符串转换为 R 中“语言”类型的公式?
- spring-boot - spring data lovelace m3 和 spring boot 2.0
- amazon-web-services - 如何提示 AWS SNS 向 Cloudformation 创建的订阅发送确认消息?
- android - 我可以从突然消失的 GO Note android 小部件中恢复我的列表吗?