cost 264 ms
將 undefined 與啟用了 strictNullChecks 的數字進行比較

[英]Compare undefined with numbers with strictNullChecks enabled

strictNullChecks是一個很好的選擇,它可以幫助開發人員避免許多潛在的運行時錯誤。 所以我最近開始在啟用此選項的情況下重構我的代碼。 但后來我遇到了一個小但有點煩人的場景: 我有使用這種語法來獲取非空數組的習慣,利用 JavaScript 功能,使用<或>比較任何undef ...

類型縮小:當 noUncheckedIndexedAccess 為真時檢查變量 object 鍵是否存在

[英]Type narrowing: checking variable object key existence when noUncheckedIndexedAccess is true

我的tsconfig.json中有"noUncheckedIndexedAccess": true 。 開關的全部要點是在訪問索引之前強制檢查該項目是否存在。 我很難用可變鍵檢查 object: 說我有以下結構:const items: Record<string, {name: string ...

有沒有告訴 typescript 所有數組元素都存在於 Map 中的好方法?

[英]Is there a good way of telling typescript all array elements exist in a Map?

假設我正在從以 id 作為鍵的對象數組創建 Map,然后從具有相同 id 的不同數組訪問 map: 如果我有“strictNullChecks”:true,那么最后一行會拋出一個“對象可能是'未定義'”錯誤,即使它永遠不會是未定義的。 有沒有辦法告訴 typescript 數組中的元素存在於 ma ...

我可以在 TypeScript 嚴格空檢查模式下禁用區分 null 和 undefined 嗎?

[英]Can I disable distinguishing between null and undefined in TypeScript strict null-checking mode?

我目前正在將大型 TypeScript 代碼庫轉換為嚴格的空檢查。 代碼庫有許多帶有可選成員的類型: 此外,它使用類型Nullable<T> = T | null Nullable<T> = T | null ,並且有很多return null語句。 現在我面臨許多編 ...

從可能是 null 和 strictNullChecks 的屬性中鍵入別名

[英]Type alias from property that might be null with strictNullChecks

我正在使用graphql-codegen/typescript-apollo-angular生成 typescript 代碼,可以在我們的 Angular 應用程序中使用。 我們決定啟用strictNullChecks ,唯一的問題是我們使用以下模式來指定 API 返回的內部節點的類型: 在我的情況 ...

使 Typescript strictNullChecks 與未定義的返回 vanilla js 函數一起使用

[英]Getting Typescript strictNullChecks to work with undefined returning vanilla js functions

使用慣用的 js 在錯誤時返回未定義,轉換為 TS 當在新的 TS 代碼中使用乘法時,我得到編譯器認為 doStuff 可以返回 undefined 的問題,但它不能。 因此,我嘗試編寫由安全 TS 代碼調用的此函數的“不安全”版本,將安全版本留給常規 js 代碼。 由於 unsafeMu ...

在 TypeScript 中的小於或大於比較中允許可以為空的操作數

[英]Allow nullable operands in less- or greater-than comparisons in TypeScript

在 JavaScript 中, 關系表達式中的空操作數被視為 0 : 但是在 TypeScript 中,如果我為f提供類型注釋並打開嚴格的空檢查,那么我會得到編譯器錯誤Object is possibly 'null' : 有沒有辦法告訴編譯器這里可以接受可為空的操作數? 我可以用f()上 ...

Typescript strictNullChecks 不窄類型

[英]Typescript strictNullChecks does not narrow type

我有一個簡單的情況,即使我明確檢查未定義, strictNullChecks也不會縮小類型。 錯誤信息是: 我如何幫助 TS 編譯器解決這個問題? TS 版本 3.7.2 ...

TypeScript:即使 strictNullChecks 為假,我是否可以檢查類型是否包含未定義?

[英]TypeScript: Can I check if a type contains undefined even when strictNullChecks is false?

我們在 redux-starter-kit 中遇到了一個問題,其中庫的用戶禁用了 strictNullChecks,並且我們的類型測試之一是短路,返回不同情況的類型。 此測試應返回 True-Parameter 或 False-Parameter,具體取決於 P 參數是否包含 undefined。 ...

打字稿strictNullChecks錯誤,當不可能

[英]Typescript strictNullChecks error when not possible

我正在嘗試為我的項目打開strictNullChecks設置,但是以下代碼片段中有一個非常奇怪的錯誤: 錯誤消息的if語句中帶有下划線的錯誤消息帶有toaster.brandName ,並帶有以下錯誤文本: error TS2532: Object is possibly 'undefi ...

為什么 TypeScript 在使用 concat 減少數組時會推斷出“從不”類型?

[英]Why does TypeScript infer the 'never' type when reducing an Array with concat?

代碼比語言說得更好,所以: 該代碼非常愚蠢,並返回一個復制的數組...... TS 抱怨 concat 的參數:TS2345:“字符串”類型的參數不可分配給“ConcatArray”類型的參數。 ...

具有嚴格打字稿的createStore

[英]createStore with strict typescript

當使用上面的代碼並strict啟用typescript時,我收到以下警告: 我理解TS嚴格模式是什么,但我不明白為什么它將我的狀態解釋為可能undefined 我能做錯什么? 或者,我怎么可能對付沒有做一些懶惰像誤差as any ? ...

帶有嚴格空值檢查的 TypeScript - 數組訪問呢?

[英]TypeScript with strict null checking - what about array access?

在 TypeScript 中,如果啟用了嚴格的 null 檢查,我希望編譯器阻止我將null或undefined值分配給變量,除非它承認null 。 但是,數組訪問似乎允許繞過此檢查。 例子: TypeScript Playground 上的可運​​行版本(注意:必須在“選項”對話框中啟用 ...

打字稿和過濾器布爾值

[英]Typescript and filter Boolean

考慮以下啟用了strictNullChecks的代碼: 由於以下原因,它無法編譯: 但絕對清楚的是, false將被.filter(Boolean)過濾掉。 與null相同的問題。 有沒有辦法(除了寫成as number[] )來標記該值不包含false或null ? ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM