当对useRef进行检查时,编译失败

问题描述 投票:0回答:1

我很好奇,为什么编译失败?存在

使用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目前是唯一的一个。

typescript webpack tsconfig ts-loader
1个回答
0
投票

可选打字链在3.7版打字稿中宣布。您使用的是旧版本吗?

© www.soinside.com 2019 - 2024. All rights reserved.