Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11830,7 +11830,12 @@ func (c *Checker) reportNonexistentProperty(propNode *ast.Node, containingType *
}

func (c *Checker) getSuggestedLibForNonExistentProperty(missingProperty string, containingType *Type) string {
container := c.getApparentType(containingType).symbol
t := c.getApparentType(containingType)
if isTupleType(t) {
// Tuple types have no symbol; use their Array or ReadonlyArray base.
t = core.IfElse(t.TargetTupleType().readonly, c.globalReadonlyArrayType, c.globalArrayType)
}
container := t.symbol
if container != nil {
featureMap := getFeatureMap()
if typeFeatures, ok := featureMap[container.Name()]; ok {
Expand Down
23 changes: 23 additions & 0 deletions tsc/internal/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,14 @@ var getFeatureMap = sync.OnceValue(func() map[string][]FeatureMapEntry {
{lib: "es2022", props: []string{"at"}},
{lib: "es2023", props: []string{"findLastIndex", "findLast", "toReversed", "toSorted", "toSpliced", "with"}},
},
"ReadonlyArray": {
{lib: "es5", props: []string{}},
{lib: "es2015", props: []string{"find", "findIndex", "entries", "keys", "values"}},
{lib: "es2016", props: []string{"includes"}},
{lib: "es2019", props: []string{"flat", "flatMap"}},
{lib: "es2022", props: []string{"at"}},
{lib: "es2023", props: []string{"findLastIndex", "findLast", "toReversed", "toSorted", "toSpliced", "with"}},
},
"Iterator": {
{lib: "es2015", props: []string{}},
},
Expand Down Expand Up @@ -1525,6 +1533,9 @@ var getFeatureMap = sync.OnceValue(func() map[string][]FeatureMapEntry {
"getOrInsertComputed",
}},
},
"ReadonlyMap": {
{lib: "es2015", props: []string{"entries", "keys", "values"}},
},
"MapConstructor": {
{lib: "es2024", props: []string{"groupBy"}},
},
Expand All @@ -1540,6 +1551,18 @@ var getFeatureMap = sync.OnceValue(func() map[string][]FeatureMapEntry {
"isDisjointFrom",
}},
},
"ReadonlySet": {
{lib: "es2015", props: []string{"entries", "keys", "values"}},
{lib: "es2025", props: []string{
"union",
"intersection",
"difference",
"symmetricDifference",
"isSubsetOf",
"isSupersetOf",
"isDisjointFrom",
}},
},
"PromiseConstructor": {
{lib: "es2015", props: []string{"all", "race", "reject", "resolve"}},
{lib: "es2020", props: []string{"allSettled"}},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
doYouNeedToChangeYourTargetLibraryReadonly.ts(7,7): error TS2550: Property 'includes' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2016' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(8,7): error TS2550: Property 'flat' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(9,7): error TS2550: Property 'flatMap' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(10,7): error TS2550: Property 'at' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2022' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(11,7): error TS2550: Property 'findLastIndex' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(12,7): error TS2550: Property 'findLast' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(13,7): error TS2550: Property 'toReversed' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(14,7): error TS2550: Property 'toSorted' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(15,7): error TS2550: Property 'toSpliced' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(16,7): error TS2550: Property 'with' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(19,15): error TS2550: Property 'toReversed' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(20,22): error TS2550: Property 'toReversed' does not exist on type 'readonly [1, 2, 3]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(23,7): error TS2550: Property 'toReversed' does not exist on type '[number, string]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(26,11): error TS2550: Property 'toReversed' does not exist on type 'T'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(38,5): error TS2550: Property 'union' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(39,5): error TS2550: Property 'intersection' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(40,5): error TS2550: Property 'difference' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(41,5): error TS2550: Property 'symmetricDifference' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(42,5): error TS2550: Property 'isSubsetOf' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(43,5): error TS2550: Property 'isSupersetOf' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(44,5): error TS2550: Property 'isDisjointFrom' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
doYouNeedToChangeYourTargetLibraryReadonly.ts(46,7): error TS2339: Property 'fill' does not exist on type 'readonly number[]'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(47,7): error TS2339: Property 'copyWithin' does not exist on type 'readonly number[]'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(48,7): error TS2339: Property 'notAnArrayMethod' does not exist on type 'readonly number[]'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(49,5): error TS2339: Property 'getOrInsert' does not exist on type 'ReadonlyMap<string, number>'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(50,5): error TS2339: Property 'getOrInsertComputed' does not exist on type 'ReadonlyMap<string, number>'.


==== doYouNeedToChangeYourTargetLibraryReadonly.ts (26 errors) ====
declare const array: ReadonlyArray<number>;
array.find;
array.findIndex;
array.entries;
array.keys;
array.values;
array.includes;
~~~~~~~~
!!! error TS2550: Property 'includes' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2016' or later.
array.flat;
~~~~
!!! error TS2550: Property 'flat' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
array.flatMap;
~~~~~~~
!!! error TS2550: Property 'flatMap' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
array.at;
~~
!!! error TS2550: Property 'at' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2022' or later.
array.findLastIndex;
~~~~~~~~~~~~~
!!! error TS2550: Property 'findLastIndex' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
array.findLast;
~~~~~~~~
!!! error TS2550: Property 'findLast' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
array.toReversed;
~~~~~~~~~~
!!! error TS2550: Property 'toReversed' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
array.toSorted;
~~~~~~~~
!!! error TS2550: Property 'toSorted' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
array.toSpliced;
~~~~~~~~~
!!! error TS2550: Property 'toSpliced' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
array.with;
~~~~
!!! error TS2550: Property 'with' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.

declare const readonlyArray: readonly number[];
readonlyArray.toReversed;
~~~~~~~~~~
!!! error TS2550: Property 'toReversed' does not exist on type 'readonly number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
([1, 2, 3] as const).toReversed();
~~~~~~~~~~
!!! error TS2550: Property 'toReversed' does not exist on type 'readonly [1, 2, 3]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.

declare const tuple: [number, string];
tuple.toReversed;
~~~~~~~~~~
!!! error TS2550: Property 'toReversed' does not exist on type '[number, string]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.

function f<T extends readonly number[]>(value: T) {
value.toReversed;
~~~~~~~~~~
!!! error TS2550: Property 'toReversed' does not exist on type 'T'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
}

declare const map: ReadonlyMap<string, number>;
map.entries;
map.keys;
map.values;

declare const set: ReadonlySet<number>;
set.entries;
set.keys;
set.values;
set.union;
~~~~~
!!! error TS2550: Property 'union' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
set.intersection;
~~~~~~~~~~~~
!!! error TS2550: Property 'intersection' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
set.difference;
~~~~~~~~~~
!!! error TS2550: Property 'difference' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
set.symmetricDifference;
~~~~~~~~~~~~~~~~~~~
!!! error TS2550: Property 'symmetricDifference' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
set.isSubsetOf;
~~~~~~~~~~
!!! error TS2550: Property 'isSubsetOf' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
set.isSupersetOf;
~~~~~~~~~~~~
!!! error TS2550: Property 'isSupersetOf' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.
set.isDisjointFrom;
~~~~~~~~~~~~~~
!!! error TS2550: Property 'isDisjointFrom' does not exist on type 'ReadonlySet<number>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2025' or later.

array.fill;
~~~~
!!! error TS2339: Property 'fill' does not exist on type 'readonly number[]'.
array.copyWithin;
~~~~~~~~~~
!!! error TS2339: Property 'copyWithin' does not exist on type 'readonly number[]'.
array.notAnArrayMethod;
~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'notAnArrayMethod' does not exist on type 'readonly number[]'.
map.getOrInsert;
~~~~~~~~~~~
!!! error TS2339: Property 'getOrInsert' does not exist on type 'ReadonlyMap<string, number>'.
map.getOrInsertComputed;
~~~~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'getOrInsertComputed' does not exist on type 'ReadonlyMap<string, number>'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
doYouNeedToChangeYourTargetLibraryReadonly.ts(46,7): error TS2339: Property 'fill' does not exist on type 'readonly number[]'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(47,7): error TS2339: Property 'copyWithin' does not exist on type 'readonly number[]'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(48,7): error TS2339: Property 'notAnArrayMethod' does not exist on type 'readonly number[]'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(49,5): error TS2339: Property 'getOrInsert' does not exist on type 'ReadonlyMap<string, number>'.
doYouNeedToChangeYourTargetLibraryReadonly.ts(50,5): error TS2339: Property 'getOrInsertComputed' does not exist on type 'ReadonlyMap<string, number>'.


==== doYouNeedToChangeYourTargetLibraryReadonly.ts (5 errors) ====
declare const array: ReadonlyArray<number>;
array.find;
array.findIndex;
array.entries;
array.keys;
array.values;
array.includes;
array.flat;
array.flatMap;
array.at;
array.findLastIndex;
array.findLast;
array.toReversed;
array.toSorted;
array.toSpliced;
array.with;

declare const readonlyArray: readonly number[];
readonlyArray.toReversed;
([1, 2, 3] as const).toReversed();

declare const tuple: [number, string];
tuple.toReversed;

function f<T extends readonly number[]>(value: T) {
value.toReversed;
}

declare const map: ReadonlyMap<string, number>;
map.entries;
map.keys;
map.values;

declare const set: ReadonlySet<number>;
set.entries;
set.keys;
set.values;
set.union;
set.intersection;
set.difference;
set.symmetricDifference;
set.isSubsetOf;
set.isSupersetOf;
set.isDisjointFrom;

array.fill;
~~~~
!!! error TS2339: Property 'fill' does not exist on type 'readonly number[]'.
array.copyWithin;
~~~~~~~~~~
!!! error TS2339: Property 'copyWithin' does not exist on type 'readonly number[]'.
array.notAnArrayMethod;
~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'notAnArrayMethod' does not exist on type 'readonly number[]'.
map.getOrInsert;
~~~~~~~~~~~
!!! error TS2339: Property 'getOrInsert' does not exist on type 'ReadonlyMap<string, number>'.
map.getOrInsertComputed;
~~~~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'getOrInsertComputed' does not exist on type 'ReadonlyMap<string, number>'.

Loading