-
-
Notifications
You must be signed in to change notification settings - Fork 669
Changed the Array.flat() definition to work with Typescript Compiler #1275
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
Conversation
I guess for definitions better use something like this: flat<U>(this: Array<Array<U>>): U[]; |
Made requested changes, thanks @MaxGraey 😄 👍 |
Interestingly, this appears to work as well flat(): T while a conditional type never yields flat(): T extends unknown[] ? valueof<T>[] : never Edit: Now it suddenly does :) |
I definitely wrote this type. Whoops! I'll remember this little trick for later. |
@MaxGraey Wdyt of flat(): T extends unknown[] ? valueof<T>[] : never to avoid the |
This is just @dcodeIO 's suggestion, removing the valueof expression which resolves the exact same type, unless I am mistaken. flat(): T extends unknown[] ? T : never; |
I guess it should be: flat(): T extends unknown[] ? typeof T[0] : this; |
Compilation will currently fail if |
Thanks for updating my PR @dcodeIO ! 😄 👍 Glad we got this in haha! 😂 |
Hello!
So when I was upgrading as-bind, I noticed that AssemblyScript wasn't working with the Typescript compiler, due to a bad definition the Typescript compiler didn't like:
So I went ahead and just modified my
node_modules
directly. I tried the type:valueof<T extends unknown[]>[]
, but that didn't work. I think this new type in this PR correctly represents what we want, and it works (ignore the red test, was just trying to test things really quick):cc @dcodeIO @MaxGraey
We may want to push a minor out to npm for this? Since this will require people to modify their node modules for the
tsc
compatibility.