-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Add nullability annotations to core.d.ts and es6.d.ts #7650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,13 +304,13 @@ interface String { | |
| * Matches a string with a regular expression, and returns an array containing the results of that search. | ||
| * @param regexp A variable name or string literal containing the regular expression pattern and flags. | ||
| */ | ||
| match(regexp: string): RegExpMatchArray; | ||
| match(regexp: string): RegExpMatchArray | null; | ||
|
|
||
| /** | ||
| * Matches a string with a regular expression, and returns an array containing the results of that search. | ||
| * @param regexp A regular expression object that contains the regular expression pattern and applicable flags. | ||
| */ | ||
| match(regexp: RegExp): RegExpMatchArray; | ||
| match(regexp: RegExp): RegExpMatchArray | null; | ||
|
|
||
| /** | ||
| * Replaces text in a string, using a regular expression or search string. | ||
|
|
@@ -813,7 +813,7 @@ interface RegExp { | |
| * Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search. | ||
| * @param string The String object or string literal on which to perform the search. | ||
| */ | ||
| exec(string: string): RegExpExecArray; | ||
| exec(string: string): RegExpExecArray | null; | ||
|
|
||
| /** | ||
| * Returns a Boolean value that indicates whether or not a pattern exists in a searched string. | ||
|
|
@@ -836,7 +836,7 @@ interface RegExp { | |
| lastIndex: number; | ||
|
|
||
| // Non-standard extensions | ||
| compile(): RegExp; | ||
| compile(): this; | ||
| } | ||
|
|
||
| interface RegExpConstructor { | ||
|
|
@@ -1108,7 +1108,7 @@ interface Array<T> { | |
| /** | ||
| * Removes the last element from an array and returns it. | ||
| */ | ||
| pop(): T; | ||
| pop(): T | undefined; | ||
| /** | ||
| * Combines two or more arrays. | ||
| * @param items Additional items to add to the end of array1. | ||
|
|
@@ -1126,7 +1126,7 @@ interface Array<T> { | |
| /** | ||
| * Removes the first element from an array and returns it. | ||
| */ | ||
| shift(): T; | ||
| shift(): T | undefined; | ||
| /** | ||
| * Returns a section of an array. | ||
| * @param start The beginning of the specified portion of the array. | ||
|
|
@@ -1519,7 +1519,7 @@ interface Int8Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -1530,7 +1530,7 @@ interface Int8Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Arnavion feel free to send a separate PR for the predicate changes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mhegazy And should I move the other commits after the first one into a separate PR as well?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a second thought, the commit messages look clear enough, so feel free to include the findIndex chances in this PR if you like or have it in a separate one. up to you.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed them from this PR. Will make another one. |
||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -1792,7 +1792,7 @@ interface Uint8Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -1803,7 +1803,7 @@ interface Uint8Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: |
||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -2066,7 +2066,7 @@ interface Uint8ClampedArray { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -2077,7 +2077,7 @@ interface Uint8ClampedArray { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: |
||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -2339,7 +2339,7 @@ interface Int16Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -2350,7 +2350,7 @@ interface Int16Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -2613,7 +2613,7 @@ interface Uint16Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -2624,7 +2624,7 @@ interface Uint16Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -2886,7 +2886,7 @@ interface Int32Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -2897,7 +2897,7 @@ interface Int32Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -3159,7 +3159,7 @@ interface Uint32Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -3170,7 +3170,7 @@ interface Uint32Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -3432,7 +3432,7 @@ interface Float32Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -3443,7 +3443,7 @@ interface Float32Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
@@ -3706,7 +3706,7 @@ interface Float64Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number; | ||
| find(predicate: (value: number, index: number, obj: Array<number>) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -3717,7 +3717,7 @@ interface Float64Array { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: number) => boolean, thisArg?: any): number | undefined; | ||
|
|
||
| /** | ||
| * Performs the specified action for each element in an array. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ interface SymbolConstructor { | |
| * Otherwise, returns a undefined. | ||
| * @param sym Symbol to find the key for. | ||
| */ | ||
| keyFor(sym: symbol): string; | ||
| keyFor(sym: symbol): string | undefined; | ||
|
|
||
| // Well-known Symbols | ||
|
|
||
|
|
@@ -320,7 +320,7 @@ interface Array<T> { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T; | ||
| find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T | undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's specced as such. (Every function that takes a callback has this problem, even the plain old Array methods like forEach)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix in another PR along with other |
||
|
|
||
| /** | ||
| * Returns the index of the first element in the array where predicate is true, and undefined | ||
|
|
@@ -331,7 +331,7 @@ interface Array<T> { | |
| * @param thisArg If provided, it will be used as the this value for each invocation of | ||
| * predicate. If it is not provided, undefined is used instead. | ||
| */ | ||
| findIndex(predicate: (value: T) => boolean, thisArg?: any): number; | ||
| findIndex(predicate: (value: T) => boolean, thisArg?: any): number | undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| /** | ||
| * Returns the this object after filling the section identified by start and end with value | ||
|
|
@@ -407,7 +407,7 @@ interface String { | |
| * If there is no element at that position, the result is undefined. | ||
| * If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos. | ||
| */ | ||
| codePointAt(pos: number): number; | ||
| codePointAt(pos: number): number | undefined; | ||
|
|
||
| /** | ||
| * Returns true if searchString appears as a substring of the result of converting this | ||
|
|
@@ -453,7 +453,7 @@ interface String { | |
| * Matches a string an object that supports being matched against, and returns an array containing the results of that search. | ||
| * @param matcher An object that supports being matched against. | ||
| */ | ||
| match(matcher: { [Symbol.match](string: string): RegExpMatchArray; }): RegExpMatchArray; | ||
| match(matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null; | ||
|
|
||
| /** | ||
| * Replaces text in a string, using an object that supports replacement within a string. | ||
|
|
@@ -723,7 +723,7 @@ interface RegExp { | |
| * that search. | ||
| * @param string A string to search within. | ||
| */ | ||
| [Symbol.match](string: string): RegExpMatchArray; | ||
| [Symbol.match](string: string): RegExpMatchArray | null; | ||
|
|
||
| /** | ||
| * Replaces text in a string, using this regular expression. | ||
|
|
@@ -800,7 +800,7 @@ interface Map<K, V> { | |
| delete(key: K): boolean; | ||
| entries(): IterableIterator<[K, V]>; | ||
| forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void; | ||
| get(key: K): V; | ||
| get(key: K): V | undefined; | ||
| has(key: K): boolean; | ||
| keys(): IterableIterator<K>; | ||
| set(key: K, value?: V): Map<K, V>; | ||
|
|
@@ -821,7 +821,7 @@ declare var Map: MapConstructor; | |
| interface WeakMap<K, V> { | ||
| clear(): void; | ||
| delete(key: K): boolean; | ||
| get(key: K): V; | ||
| get(key: K): V | undefined; | ||
| has(key: K): boolean; | ||
| set(key: K, value?: V): WeakMap<K, V>; | ||
| readonly [Symbol.toStringTag]: "WeakMap"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a guarantee that compile returns your subclass if you subclass RegExp, so it should return plain
RegExpinstead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to ES specs it should return the
thisvalue of thecompile()call.So using
thistype here seems like the correct thing to do.BTW: this method is deprecated so hopefully it won't matter much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concur 👍