mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-05 08:13:06 +08:00
`implements Acyclic` resolved to Record<never, never>, and the frontend indexes implemented types as class protocols by symbol, so every Record value in the program took checked identity (on tsc-ts: Int32 field contracts failed with SC7003). The default is now AcyclicObject, an empty interface only @scriptc/types declares, and type arguments in heritage clauses are reported (they would make a class implement its own type). Corpus 4642 stores an Acyclic class with an Int32 field in a Record. explainCycle picks the shortest cycle through the unit and a mutable edge (BFS distances forward and backward within the component): on tsc-ts `Node.parent -> Node` instead of a 20-step path through the checker.
19 lines
503 B
TypeScript
19 lines
503 B
TypeScript
// Acyclic is checked on classes, interfaces and object type aliases.
|
|
// Elsewhere it would promise something scriptc does not check, so the build
|
|
// reports it.
|
|
import type { Acyclic } from "@scriptc/types";
|
|
|
|
interface Item {
|
|
name: string;
|
|
}
|
|
|
|
// A type argument would make the class implement its own type.
|
|
class Box implements Acyclic<Item> {
|
|
name = "box";
|
|
}
|
|
|
|
const item: Acyclic<Item> = { name: "a" };
|
|
const items: Acyclic<Item>[] = [item];
|
|
|
|
console.log(item.name, items.length, new Box().name);
|