尝试将 Material 主题配置为使用我自己的字体和自定义字体粗细/大小作为 Typography 组件。对于该fontWeight部分,我只想能够输入100/200/300/400/500/600/700每个特定材料排版变体的选项,但是,它专门接受一个“字符串”,显然只能是normal/bold/bolder/lighter
并normal == 400在bold == 700跳过我需要的 500 和 600时使情况变得更糟
typography: {
fontFamily: "MyCustomFont",
fontWeightLight: 200,
fontWeightRegular: 400,
fontWeightMedium: 500,
useNextVariants: true,
h1: {
fontSize: "1.25rem",
fontWeight: "bold",
lineHeight: "1.2em"
},
h2: {
fontSize: "1.75rem",
fontWeight: "normal",
lineHeight: "1.2em"
},
}
Run Code Online (Sandbox Code Playgroud) 由于智能感知速度极慢,我的 Macbook Pro 上的 VSCode 几乎无法使用。这包括:
例如,我会显示错误。像“变量未定义”之类的东西或者简单的东西。但当我去重写代码时,VSCode 花了很长时间才跟上。有时我必须让它静置 40-50 秒,然后它才能跟上我的更改。将鼠标悬停在打字稿类型上有时实际上是不可能的,而且完全无用。下面是“滞后”的屏幕截图 - 进行了更改,但卡住了 30 秒以上:
VSCode 版本:1.47.3
结果是我想要什么:

我在一个容器中有三个元素,display: flex我希望左侧的项目与左侧对齐,右侧的项目与右侧对齐。中心项目在中心对齐。
space-between是不是修复。这不是我要找的解决方案。这是因为元素的宽度不同。即使宽度不同,我仍然希望中间元素居中。
这可以用包装纸固定。然后flex: 1在包装纸上放一个,然后在这些包装纸内放元素本身。同样,这不是我要寻找的解决方案。我无法使用包装器。
.parentContainer {
display: flex;
justify-content: center;
align-items: center;
}
.parentContainer > *{
background: red;
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<div class="parentContainer">
<div class="left">small</div>
<div class="middle">medium element here</div>
<div class="right">longer element is here too</div>
</div>Run Code Online (Sandbox Code Playgroud)
将 Typescript 与 MUI+Styled-Components 一起使用,由于类型错误,您必须直接将 props 传递给 MUI 元素......
const Index = () => {
return (
<StyledButton
variant="contained"
>
Hello World
</StyledButton>
)}
const StyledButton = styled(Button)`
background: red;
color: white;
`;
Run Code Online (Sandbox Code Playgroud)
但是,这会出现以下错误:
输入'{孩子:字符串;变体:“包含”;}' 不可分配给类型 '(IntrinsicAttributes & Pick>) | PropsWithChildren, "表单" | "风格" | “标题” | ... 更多 284 ... | "variant"> & Partial<...>, "form" | ... 286 更多... | “变体”> & { ...; } & { ...; }) | (IntrinsicAttributes & ... 3 more ... & { ...; …
假设你有一个对象类型:
type Person = {
name?: string;
color?: string;
address?: string;
}
Run Code Online (Sandbox Code Playgroud)
但是,您想将该类型更改为以下类型,您知道名称和颜色将存在。
type Person = {
name: string;
color: string;
address?: string;
}
Run Code Online (Sandbox Code Playgroud)
因此,有这样的函数
const throwIfUndefined = (
object: {[key: string]: any},
requiredKeys: string[]
): ReturnTypeHere => {
for (const key of requiredKeys) {
if (!object[key]) throw new Error("missing required key");
}
return object;
};
Run Code Online (Sandbox Code Playgroud)
输入函数参数以及返回类型 ( ReturnTypeHere) 的正确方法是什么?如果写得正确,下面的代码将 1) 抛出错误 2) 控制台记录名称。它永远不会控制台日志未定义。
const person = {...}
const requiredKeys = ["name", "color"];
const verifiedPerson = throwIfUndefined(person, requiredKeys);
console.log(verifiedPerson.name)
Run Code Online (Sandbox Code Playgroud) typescript ×4
javascript ×3
material-ui ×2
reactjs ×2
css ×1
css3 ×1
flexbox ×1
html ×1
ide ×1