Compiler examples
These examples distinguish emitted TypeScript syntax from the bounded families that tscc also checks. They are representative of the current preview contract, not promises of full tsc compatibility.
Typed functions and contextual callbacks
type Mapper = (value: number, index?: number) => string;
const format: Mapper = (value, index = 0) =>
`${index}:${value}`;
function apply(value: number, mapper: Mapper): string {
return mapper(value, 1);
}
apply(42, value => value.toString()); Callable aliases, annotated callable variables, typed function declarations and direct inline callback expressions participate in bounded argument, arity, parameter and result checking.
Structural objects and interfaces
interface Named { name: string; }
interface Scored extends Named { score: number; }
type Formatter = {
prefix?: string;
format(value: number): string;
};
const player: Scored = { name: "Ada", score: 42, active: true };
const formatter: Formatter = {
format(value) { return value.toString(); }
}; Required and optional properties, methods, function-valued properties, compatible interface merging and bounded inheritance are checked structurally. Extra source properties are intentionally compatible; excess-property freshness is not implemented.
Index and call signatures
interface Scores {
[name: string]: number;
}
interface Parse {
(source: string): number;
}
const scores: Scores = { ada: 42 };
const answer: number = scores["ada"];
const parse: Parse = source => 42;
parse("answer"); Exact string keys and bounded string/number index reads are checked. Symbols, overload sets and indexed writes remain outside the slice.
Arrays and tuples
const primes: number[] = [2, 3, 5, 7];
const first: number = primes[0];
const entry: [string, number] = ["answer", 42];
const label: string = entry[0];
const value: number = entry[1];
const width: number = entry.length; Contextual literals, numeric reads and length are checked. Array methods, indexed writes, readonly arrays and optional/rest tuples are not implied.
Enums, namespaces and parameter properties
enum Mode { Fast, Safe = 3 }
namespace Metrics {
export const enabled = true;
}
class Point {
constructor(public x: number, readonly y: number) {}
}
console.log(Mode.Safe, Metrics.enabled, new Point(20, 22).x); These are runtime-bearing emission transforms. Their presence does not mean class or namespace types are fully checked.
Cross-module checked types
// model.ts
export interface Result { value: number; }
export type Compute = (left: number, right: number) => Result;
// main.ts
import { Result, Compute } from "./model.js";
const add: Compute = (left, right) => ({ value: left + right });
const result: Result = add(20, 22); TCP3 propagates cloned callable and structural identities through relative named imports. Package resolution, declaration-file libraries, path mappings and unit-global type identity remain outside the preview.