# freeze-types

> Lock down the types of object/array properties.

Latest version **0.1.1** (published 2017-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install freeze-types
pnpm add freeze-types
yarn add freeze-types
bun add freeze-types
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-11-17 |
| First published | 2017-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jeffmcmahan |

## Links

- npm: https://www.npmjs.com/package/freeze-types
- Repository: https://github.com/jeffmcmahan/freeze-types
- Homepage: https://github.com/jeffmcmahan/freeze-types#readme
- Issues: https://github.com/jeffmcmahan/freeze-types/issues
- npm.io page: https://npm.io/package/freeze-types

## Recent versions

- 0.1.1 (latest) — 2017-11-17

## README

# FreezeTypes
Take any object value and lock down the types of its writable properties.

```js
const obj = freezeTypes({
	name: 'John Smith'
})

obj.name = 'Jimmy'
obj.name = 4 // throws
```

```
TypeError: Cannot set type-frozen property name from type String to type Number.

	.../.../your-js-file.js:75:54
	...
```

## ES5/6 Class Support
```js
class User {
	constructor(name, age) {
		this.name = name
		this.age = age
		freezeTypes(this)
	}
}

const user = new User
user.name = 35 		// throws
user.age = 'Jimmy' 	// throws
```

## Extend and re-freeze.
Type-frozen objects are not meant to behave as if they were *statically* typed. Instead, they are freely extendable, and after any extension, an object can be re-frozen, as follows:

```js
const obj = {name: 'John Smith'}
freezeTypes(obj)

obj.age = 24 		// Extend the object with an age property.
freezeTypes(obj) 	// Re-freeze types to capture the extension.

obj.age = false 	// throws
```

However, once frozen, an object cannot be un-frozen (except by painful, fussy effort). Moreover, a frozen property cannot be deleted (frozen properties are non-configurable).

---
_Source: https://npm.io/package/freeze-types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
