简体   繁体   English

使用 fetch api 对“任何”值的不安全分配/成员访问

[英]Unsafe assignment/member access of an `any` value with fetch api

I don't know how to correct the linting error.我不知道如何纠正掉毛错误。 Perhaps I just don't fully understand the issue, but it doesn't seem to matter what I do.也许我只是不完全理解这个问题,但我做什么似乎并不重要。 I just can't seem to get rid of the error.我似乎无法摆脱错误。 I'd rather not disable the rule unless the issue is that my linting rules are just too strict.我宁愿不禁用该规则,除非问题是我的 linting 规则太严格了。

I'm using this in a fetch with google geocode api.我正在使用 google geocode api fetch它。

fetch(uri)
        .then(res => (res.json() as Promise<google.maps.GeocoderResponse>))
        .then(data => {
            const result = data.results[0].geometry;
            // Unsafe assignment of an `any` value.
            // Unsafe member access .results on an `any` value.

        })

Any help would be appreciated.任何帮助,将不胜感激。

Have you tried specifying the type of data ?您是否尝试过指定data类型?

.then((data: <DEFINE TYPE HERE>)  => {
            const result = data.results[0].geometry;
        })

try this it will work试试这个它会工作

(data as google.maps.GeocoderResponse).results[0].geometry

else define custom type in typescript for geocoderresponse and use it.否则在 typescript 中为 geocoderresponse 定义自定义类型并使用它。 url 网址

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到此打字稿错误:对任何值不安全的成员访问 [key] - Getting this typescript error: Unsafe member access [key] on an any value 任何值上的 eslint 错误不安全成员访问 ['content-type'] - eslint error Unsafe member access ['content-type'] on an any value @typescript-eslint/no-unsafe-assignment:任何值的不安全赋值 - @typescript-eslint/no-unsafe-assignment: Unsafe assignment of an any value ESLint:“any”的不安全分配和“any”类型值的不安全调用 - ESLint: Unsafe assignment of an `any` and Unsafe call of an `any` typed value 任何值 ESLint 错误的 Typescript 不安全分配 - Typescript Unsafe Assignment of An Any Value ESLint Error Any 值三元运算符的不安全赋值 - Unsafe assignment of an Any value ternary operator 当类型应该隐含时,“任何”值的不安全分配? - Unsafe assignment of "any" value when type should be implicitly implied? 不安全的成员访问<method>在 `any` 值上。 `this` 在编译器项目的 TypeScript 中被键入为 `any`。 如何为 TypeScript 构建 mixin?</method> - Unsafe member access <method> on an `any` value. `this` is typed as `any` in TypeScript for compiler project. How to architect mixins for TypeScript? Typescript React 输入 onchange 不安全赋值 'any' - Typescript React input onchange unsafe assignment 'any' 将 react-transition-group 与 TypeScript 一起使用时出现“任何值的不安全分配” - "Unsafe assignment of an any value" when using react-transition-group with TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM