Skip to content

Array<T>: a constructor taking the length - #40

Merged
ASDAlexander77 merged 1 commit into
mainfrom
array-count-constructor
Oct 26, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
array-count-constructor

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

new Array<int>(10) makes an array of ten elements, all zero:

const a = new Array<int>(10);
assert(a.length == 10 && a[0] == 0);

Array<T> gets a second constructor, constructor(count: int = 0), next to the existing constructor(private data: T[] = []). A T[] argument and new Array<T>() still use the first one.

Depends on ASDAlexander77/TypeScriptCompiler#696 (constructor overloads). Without it, this fails to compile with can't resolve name: data.

Tests

  • New: tests/array_count.ts. Passes under the JIT and as an --opt_level=3 exe.
  • array_splice, array_class_splice, and the TypedArray subclass (super(data)) still pass.
  • For these runs lib.generics.ts was copied into __build by hand. The default library has not been rebuilt with build.bat, and the full tests.ps1 suite has not been run.

🤖 Generated with Claude Code

`new Array<int>(10)` makes an array of ten elements. It needs the
compiler's constructor overloads (TypeScriptCompiler,
constructor-overloads).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 7386285 into main Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant