Civet Debuts TypeScript Superset Trading Typing for Types
Original title: Civet: TypeScript superset that favors more types and less typing
58AI Score
Civet is a modern superset of TypeScript built around a 'more types, less typing' philosophy, compiling concise syntax down to standard TypeScript. It ships plugins for Vite, esbuild, Babel, Jest and Bun, plus a VSCode extension, online playground and Solid templates to lower adoption friction.
Related Entities
Full Report
Contents5 sections
Civet
The modern way to write TypeScript.
- Documentation
- Changelog
- Design Philosophy
- Civet Playground
- Civet VSCode Extension
- Discord Server
- Plugins for
Vite, esbuild, Astro, Farm, Rolldown, Rollup, Webpack,
ESM/CJS loader,
Babel,
Jest,
Gulp,
Bun,
<script>tag - Starter templates for Solid (older) and Solid Start
Quickstart Guide
# Install
npm install -g @danielx/civet
# Run Civet code directly in a REPL
civet
# Transpile typed Civet code into TypeScript in a REPL
civet -c
# Compile Civet source file to TypeScript
civet < source.civet > output.ts
# Execute a .civet script
civet source.civet ...args...
# Execute a .civet source file in node
node --import @danielx/civet/register source.civet
# Type check entire project, which requires TypeScript installed
npm install -g typescript
civet --typecheck
Code Sample
ts, {CompilerOptions} from typescript
DefaultCompilerOptions : CompilerOptions :=
allowNonTsExtensions: true
allowJs: true
target: ts.ScriptTarget.Latest
moduleResolution: ts.ModuleResolutionKind.NodeJs
module: ts.ModuleKind.CommonJS
allowSyntheticDefaultImports: true
experimentalDecorators: true
fileCache : Record<string, any> := {}
createCompilerHost := (options: CompilerOptions, moduleSearchLocations : string[]) ->
fileExists := (fileName: string) : boolean ->
fileCache[fileName]?
readFile := (fileName: string) ->
fileCache[fileName]Overview
Civet is essentially a tasteful superset of TypeScript.
Implementations of New and Proposed ES Features
See the documentation for examples of these and other features.
- Pattern matching (based on TC39 proposal)
switchcan match patterns like[{type: "text", name}, ...rest]
- Pipe operator (based on F# pipes, Hack pipes and the TC39 proposal)
data |> Object.keys |> console.logequivalent toconsole.log(Object.keys(data))- Use single-argument arrow functions or
&shorthand to specify how to use left-hand side |> await,|> yield, and|> return(at end) for wrapping left-hand side with that operation
- Short function block syntax like Ruby symbol to proc, Crystal, Elm record access
- Access:
x.map &.nameorx.map .name→x.map(a => a.name) - Nested access + slices:
x.map &.profile?.name[0...3]→x.map(a => a.profile?.name.slice(0, 3)) - Function call:
x.map &.callback a, b→x.map($ => $.callback(a, b)) - Unary operators:
x.map !!&→x.map($ => !!$) - Binary operators:
x.map &+1→x.map($ => $+1)
- Access:
- Object literal shorthand
{foo()}→{foo: foo()},{props.foo}→{foo: props.foo}{`${x}${y}`: z}→{[`${x}${y}`]: z}data.{x,y}ordata{x,y}→{x: data.x, y: data.y}- Flagging shorthand based on from LiveScript:
{+debug, -live, !verbose}→{debug: true, live: false, verbose: false}
- Custom infix operators from any two-argument function
doexpressions,ifexpressions,forexpressions
Convenience for ES6+ Features
- Const assignment shorthand:
a := b→const a = b,{a, b} := c→const {a, b} = c - Let assignment shorthand:
a .= b→let a = b - Typed versions of above:
a: number .= 5→let a: number = 5(but note thata: number = 5is the object literal{a: (number = 5)}). @#id→this.#idshorthand for private identifiersimportshorthand:x from ./x→import x from "./x"- Dynamic
importshorthand:import './x'not at top level (e.g.await import './x'or inside a function) →import('./x') - Optional import rename syntax that corresponds to destructuring rename
import {x: y} from "./z"→import {x as y} from "./z". You can still useasto be compatible with existing ES imports. exportshorthand:export x, y→export {x, y}- Triple backtick Template Strings remove leading indentation for clarity
- Class constructor shorthand
@( ... ) - ClassStaticBlock
@ { ... } <asextendsshorthand///Block RegExp like Python re.X
(注:更多技术实现细节与完整 API 文档请查阅原项目 README)