-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support argument list and array splices ...xs
#103
Comments
The way I'm thinking to represent that is by using a new type form: case class Splice(elems: Ls[SimpleType])(val prov: TypeProvenance) extends BaseType For example, A complication will arise when computing the |
I don't quite understand this part: |
Oh yeah you're actually right, my bad. Better use a clean |
Basically what I found that in TypeScript:
So, if we want to follow TypeScript, the case class SpliceType(left: Ls[SimpleType], rep: Option[SimpleType], right: Ls[SimpleType])(val prov: TypeProvenance) extends BaseType We can also continue with the original one and reject the ones that are ambiguous... |
I don't think that's true. Here's an example valid JS program: function myFunction(v, w, x, y, z) { }
let args = [0, 1];
myFunction(-1, ...args, 2, ...[3]); The TS version needs some more type annotations, but also works: function myFunction(v: number, w: number, x: number, y: number, z: number) { }
let args: [0, 1] = [0, 1];
myFunction(-1, ...args, 2, ...([3] as [3]));
I don't think that's true either. Here's an example valid TS program: let arr1 = [0, 1, 2];
let arr2 = [3, 4, 5];
arr1 = [...arr2, ...arr1]; Maybe here you're talking about patterns and parameter lists, which should indeed have such restrictions. We can add a check for this restriction later. In any case, the internal type representations should assume the general form. |
Oh yes, I think I'm talking patterns when defining functions and type annotations 😂 let ys: [number, number, ...number[], string, ...boolean[]]
function fx(a: string, ...b: string[], c: number) {}
function fy(a: string, ...b: string[], ...c: number[]) {} So only patterns have restrictions, but spreading lists is not restricted... |
Support typing and type inference for argument list and array splices.
Examples:
f(a, b, ...c, d, ...e)
and[a, b, ...c, d, ...e]
.Type inference should do its best to infer the most precise types, but it may sometimes hit ambiguities, such as when constraining
(a, b) <: (...?s, ...?t)
. In such cases, reporting a type error will be fine, prompting users to write a type annotation in order to remove the ambiguity.The text was updated successfully, but these errors were encountered: