Skip to content

Empty arrays as inputs with omitted default context loose this context for some reason #2405

Open
@MaxGraey

Description

@MaxGraey

Simple example:

class A<T> {
  foo<U extends ArrayLike<T> = Array<T>>(a: U): U {
    return a;
  }
}

const a = new A<string>();
const r = a.foo([]); // `r` should infer as Array<string> but it deduced as `Array<usize>` instead
// a.foo<string[]>([]) // <- works

export function check(): bool {
  return r instanceof Array<string>; // will return `false` instead `true`
}

AssemblyScript has a pessimistic rule. When empty array literal can't be inferred value type it presents this as usize instead any (TS-way). But this is not that situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions