Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Support structural constructor return types with static members

Aperta
#1,372 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
compilers

Direzione di ricerca

Start by tracing how the compiler handles structural constructor types and static members during IR compilation, then follow the computed-expression extension path from Reproduction B. The issue gives two standalone repros and commands to build them with --emit=ir; run both to inspect the failures. Done means both compile and their native outputs match Node’s outputs, including the constructor intersection case.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Feature request for class values described by structural constructor types. The generic class factory example from #1241 now compiles, but exposing a constructor through an explicit structural return type still fails. These two examples belong to the same requested API surface; I have not established whether they need the same compiler fix.

Tested against scriptc main at a7e3a9d0aa (package version 0.3.6), macOS arm64, Node.js 24.22.0. The examples pass TypeScript 5.9.3 with strict mode, ESNext target, Bundler module resolution, and noEmit.

Reproduction A: constructor signature with a static member
type DescribedClass = { readonly schema: unknown; new (): unknown };
class Item {
  static readonly schema = { name: true };
  value = 42;
}
function classOf(): DescribedClass { return Item; }
console.log(JSON.stringify(classOf().schema));

Node prints {"name":true}. scriptc exits 1 during IR compilation:

SC2001: values of type 'DescribedClass' cannot be compiled yet (supported: number, string, boolean, arrays, Maps, Sets, RegExp, read-only Date values, functions, classes, records, unions of those, and 'unknown')
Reproduction B: extending a factory whose return type is a constructor intersection
type Struct<S> = (abstract new () => S) & { readonly decode: (value: unknown) => S };
function struct<S>(value: S): Struct<S> {
  abstract class Base {
    static decode(_input: unknown): S { return value; }
  }
  return Base as Struct<S>;
}
class Counter extends struct({ value: 42 }) {}
console.log(Counter.decode(null).value);

Node prints 42. scriptc exits 1 during IR compilation:

SC1090: extending computed expressions are not supported yet
SC2008: values of type 'Struct<{ value: number; }>' cannot be compiled: this intersection resolves to no runtime shape
Commands

Save each example separately as repro.ts. From a scriptc checkout with the compiler built:

node repro.ts
node --import tsx packages/cli/src/main.ts build repro.ts --emit=ir -o /tmp/repro.ir.json
Expected behavior and use case

Support passing and returning class values through a constructor signature that also describes their static members, including the factory-returned intersection above. Native execution should match the Node outputs.

Schema libraries use this pattern to expose static metadata or decoders together with a schema-derived instance type. This is a follow-up support request beyond the inferred factory return type in #1241, not a report that its original reproducer is still broken.

Lingua principale
TypeScript
Stelle
6.2k
Fork
183
Merge medio
3h 22m
PR unite (30g)
904

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/scriptc

Tutte le issue di vercel-labs/scriptc

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.