我很好奇,为什么编译失败?存在
使用React的[useRef
。
下面是编译时的错误:
Module parse failed: Unexpected token (7:12)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
* ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
| const ref = useRef(null)
| const handleClickOutside = event => {
> if (ref?.current) {
| setFocused(ref.current.contains(event.target));
| }
并且如果我删除?
中的ref?.current
,则编译成功。发生了什么事,并且缺少if(ref && ref.current)
前进的方向。是否有要使用的特定Webpack插件? TypescriptDeclarationPlugin
目前是唯一的一个。
可选打字链在3.7版打字稿中宣布。您使用的是旧版本吗?