Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ahh/src/default.ts>def

Opinionated idiomatic features for TypeScript.
Latest
function def
import { def } from "https://deno.land/x/ahh@v0.14.0/src/default.ts";

Returns the default value for a Default object.

Examples

Example 1

import { assertEquals } from "../test_deps.ts";
import { def } from "./default.ts";

class Vec2 {
  x: number;
  y: number;

  constructor();
  constructor(v: number);
  constructor(x?: number, y?: number) {
    this.x = x ?? 0;
    this.y = y ?? x ?? 0;
  }
}

assertEquals(def(Vec2), new Vec2());

Returns the default value for the undefined primitive.

Examples

Example 1

import { assert } from "../test_deps.ts";
import { def } from "./default.ts";

assert(def("undefined") === undefined);

Parameters

primitive: "undefined"

Returns

undefined

Returns the default value for the null object.

Examples

Example 1

import { assertEquals } from "../test_deps.ts";
import { def } from "./default.ts";

assertEquals(def("null"), null);

Parameters

object: "null"

Returns the default value for the boolean primitive.

Examples

Example 1

import { assert } from "../test_deps.ts";
import { def } from "./default.ts";

assert(def("boolean") === false);

Parameters

primitive: "boolean"

Returns

false

Returns the default value for the number primitive.

Examples

Example 1

import { assert } from "../test_deps.ts";
import { def } from "./default.ts";

assert(def("number") === 0);

Parameters

primitive: "number"

Returns the default value for the bigint primitive.

Examples

Example 1

import { assert } from "../test_deps.ts";
import { def } from "./default.ts";

assert(def("bigint") === 0n);

Parameters

primitive: "bigint"

Returns the default value for the string primitive.

Examples

Example 1

import { assert } from "../test_deps.ts";
import { def } from "./default.ts";

assert(def("string") === "");

Parameters

primitive: "string"