Search Terms
Suggestion
tsconfig: noUncheckedIndexedAccess is a good new feature, but whole project level setting is too coarse-grained to use.
traditional { [index :number] :undefined | T } could control that in api level. but not like noUncheckedIndexedAccess, it makes arr[0] = undefined valid which is not intended.
I wait the feature so long, but when I open noUncheckedIndexedAccess, there are too many too many too many errors, which cause trouble far more than help.
so in fact, we need a feature that makes T-only when writing, and T | undefined when reading.
Use Cases
Examples
maybe something like:
type T = string;
const myArray :{
optional [index :number] :T
optional item :T
};
myArray[0]// T | undefined
myArray.item// T | undefined
myArray.item = undefined// error, undefined is readonly
if ( 'item' in myArray ) {
myArray.item// T
}
? to be rethinked would be best, but it took too much historical burden.
Checklist
My suggestion meets these guidelines:
Search Terms
Suggestion
tsconfig: noUncheckedIndexedAccessis a good new feature, but whole project level setting is too coarse-grained to use.traditional
{ [index :number] :undefined | T }could control that in api level. but not likenoUncheckedIndexedAccess, it makesarr[0] = undefinedvalid which is not intended.I wait the feature so long, but when I open
noUncheckedIndexedAccess, there are too many too many too many errors, which cause trouble far more than help.so in fact, we need a feature that makes
T-only when writing, andT | undefinedwhen reading.Use Cases
Examples
maybe something like:
?to be rethinked would be best, but it took too much historical burden.Checklist
My suggestion meets these guidelines: