type Word = "foo" | "bar" | "baz";
const schema = {
foo: ["foo"] as const,
bar: ["bar"] as const,
baX: ["bar", "baz"] as const,
};
const testFn = (schemaKey: keyof typeof schema, word: Word) => {
const array = schema[schemaKey]
array.includes(word);
// ^
// TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
// Type 'string' is not assignable to type 'never'
}
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?这对我来说似乎很愚蠢……还是我遗漏了什么?我如何合理地解决这个问题?我只是断言从不,还是有隐藏的警告?
我正在研究 React 项目,其中组件具有以下文件结构:
ComponentName/
??? ComponentName.jsx
??? possiblySomeOtherFiles.js/jsx
??? index.js
Run Code Online (Sandbox Code Playgroud)
和index.js 重新导出 ComponentName.jsx 像这样:
import ComponentName from './ComponentName'
export default ComponentName
Run Code Online (Sandbox Code Playgroud)
我想为此创建一个实时模板,如下所示:
import $COMPONENT_NAME$ from './$COMPONENT_NAME$'
export default $COMPONENT_NAME$
Run Code Online (Sandbox Code Playgroud)
我如何获得 的价值$COMPONENT_NAME$?我想从当前目录的名称中获取它,但无法弄清楚如何做到这一点。
我尝试将变量设置为groovyScript("_editor.getVirtualFile().getPath()")和此处groovyScript("new File('.').absolutePath")提示,但都返回:
groovy
/
lang / GroovyShell
Run Code Online (Sandbox Code Playgroud)
到目前为止,这甚至可能吗?
我有一个组件当前使用useDrag钩子连接到react-dnd。除了预览之外,它运行良好。我想实现useDragLayer来看看它是否能帮助解决我的预览问题,正如许多在线线程所建议的那样。
这是我当前的(简化的)useDrag 实现:
const [{ isDragging }, connectDragSource, connectPreview] = useDrag({
item,
collect: monitor => ({
isDragging: monitor.getItem()?.index === item.index,
})
})
return (
<Wrapper ref={connectPreview} isDragging={isDragging}>
<DragHandle ref={connectDragSource} />
</Wrapper>
)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我该如何使用useDragLayer,以有助于我的预览?文档示例对我来说毫无意义......
如何使用useDragLayerapi 连接渲染的组件?useDragLayer不返回拖动源和预览连接器函数(就像useDrag在返回数组的索引 1 和 2 上所做的那样),并且其收集函数也不提供DragSourceConnector实例。那么调用钩子/返回值后我该如何处理呢?
在 中,在没有依赖项的数组@lexical/react中注册编辑器命令是否会造成重大损失(性能或其他) ?useEffect
useEffect(() => {
const unsubscribe = editor.registerCommand(
KEY_ENTER_COMMAND,
event => { /* ... */ },
COMMAND_PRIORITY_HIGH
)
return unsubscribe
})
Run Code Online (Sandbox Code Playgroud)
这是对 的内部要求Lexical,还是仅仅是调用一个额外的简单函数的问题?或者这种方法还有其他缺点吗?