Skip to content

TypedArrays: type thisArg correctly and other issues #18425

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

Closed
NaridaL opened this issue Sep 13, 2017 · 5 comments
Closed

TypedArrays: type thisArg correctly and other issues #18425

NaridaL opened this issue Sep 13, 2017 · 5 comments
Labels
Fixed A PR has been merged for this issue

Comments

@NaridaL
Copy link
Contributor

NaridaL commented Sep 13, 2017

For example, UInt8Array.find

// currently:
find(
    predicate: (value: number, index: number, obj: Array<number>) => boolean, 
    thisArg?: any): number | undefined;
// better:
find<Z = undefined>(
    predicate: (this: Z, value: number, index: number, obj: this) => boolean,
    thisArg?: Z): number | undefined;

All the variants have the same issues. It seems like it would be a good idea to refactor them to:

interface TypedArray<ArrType> {
// find etc
}
interface UInt8Array extends TypedArray<UInt8Array> {}
interface UInt16Array extends TypedArray<UInt16Array> {}
// etc
@mhegazy
Copy link
Contributor

mhegazy commented Sep 14, 2017

We have explicitly removed the this types from arrays in #16223 #18116. you can still add the overloads locally if you so chose.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 14, 2017
@NaridaL
Copy link
Contributor Author

NaridaL commented Sep 14, 2017

OK. Note that the callback parameter obj is currently wrong, it's Array<number>, when it should be this.

Would the refactoring with TypedArray help from a performance standpoint?

@mhegazy
Copy link
Contributor

mhegazy commented Sep 14, 2017

I do not think you need this, you jsut need Int32Array or Int64Array, etc.. a PR would be appreciated.

@NaridaL
Copy link
Contributor Author

NaridaL commented Sep 14, 2017

this would be more accurate in the unlikely case that you subclass a typed array.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 14, 2017

yes, but will turn all these types into generic types. this costs more in terms of memory and in execution. and since this is the standard library everyone pays for the cost even if they never subclass typed arrays.

NaridaL added a commit to NaridaL/TypeScript that referenced this issue Sep 14, 2017
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Sep 18, 2017
@mhegazy mhegazy added this to the TypeScript 2.6 milestone Sep 18, 2017
NaridaL added a commit to NaridaL/TypeScript that referenced this issue Sep 18, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants