Skip to content

Commit

Permalink
feat: add UUID model
Browse files Browse the repository at this point in the history
Sets up a basic TypeScript project which contains a UUID type.
  • Loading branch information
thewilkybarkid committed Apr 5, 2022
1 parent b12e639 commit 46daf4c
Show file tree
Hide file tree
Showing 11 changed files with 4,067 additions and 828 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,22 @@ jobs:

- name: 'Run formatter'
run: npm run format

typecheck:
runs-on: ubuntu-20.04

steps:
- name: 'Checkout code'
uses: actions/checkout@v2

- name: 'Set up Node.js'
uses: actions/setup-node@v2
with:
node-version: 16
cache: ${{ !env.ACT && 'npm' || '' }}

- name: 'Install dependencies'
run: npm ci

- name: 'Run typechecker'
run: npm run typecheck
2 changes: 2 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"arrowParens": "avoid",
"importOrder": ["^[./]"],
"importOrderSortSpecifiers": true,
"printWidth": 120,
"semi": false,
"singleQuote": true,
Expand Down
4,780 changes: 3,954 additions & 826 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
"devDependencies": {
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"@trivago/prettier-plugin-sort-imports": "^3.2.0",
"@tsconfig/recommended": "^1.0.1",
"@types/node": "^16.11.26",
"dtslint": "github:gcanti/dtslint#2c3c3487e7650d6ca90c2877dbbd7c4c08360d0d",
"husky": "^7.0.4",
"npm-run-all": "^4.1.5",
"prettier": "^2.6.2",
"prettier-plugin-sh": "^0.10.0"
"prettier-plugin-sh": "^0.10.0",
"typescript": "^4.6.3"
},
"scripts": {
"format": "prettier --ignore-unknown --check '**'",
"format:fix": "npm run format -- --write",
"prepare": "which husky && husky install || true"
"prepare": "which husky && husky install || true",
"typecheck": "npm-run-all --aggregate-output --continue-on-error --parallel typecheck:*",
"typecheck:dtslint": "dtslint test-d",
"typecheck:tsc": "tsc --noEmit"
}
}
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @since 0.1.0
*/

// -------------------------------------------------------------------------------------
// model
// -------------------------------------------------------------------------------------

/**
* @category model
* @since 0.1.0
*/
export type Uuid<V extends UuidVersion = UuidVersion> = string & UuidBrand

type UuidVersion = 1 | 2 | 3 | 4 | 5

interface UuidBrand {
readonly Uuid: unique symbol
}
1 change: 1 addition & 0 deletions test-d/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TypeScript Version: 4.0
Empty file added test-d/ts4.0/index.d.ts
Empty file.
19 changes: 19 additions & 0 deletions test-d/ts4.0/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as _ from '../../src'

declare const uuid: _.Uuid

//
// Uuid
//

declare const uuid1: _.Uuid<1>
declare const uuid2: _.Uuid<2>
declare const uuid3: _.Uuid<3>
declare const uuid4: _.Uuid<4>
declare const uuid5: _.Uuid<5>
// $ExpectError
declare const uuid6: _.Uuid<6>

const uuidToString: string = uuid
// $ExpectError
const stringToUuid: _.Uuid = 'foo'
16 changes: 16 additions & 0 deletions test-d/ts4.0/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"noEmit": true,
"strict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitReturns": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"target": "es5",
"lib": ["es2015", "dom", "dom.iterable"]
}
}
22 changes: 22 additions & 0 deletions test-d/ts4.0/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"array-type": false,
"no-unnecessary-generics": false,
"member-access": false,
"no-empty-interface": false,
"no-arg": false,
"no-object-literal-type-assertion": false,
"no-unnecessary-class": false,
"radix": false,
"no-angle-bracket-type-assertion": false,
"object-literal-shorthand": false,
"prefer-object-spread": false,
"whitespace": false,
"use-default-type-parameter": false,
"no-relative-import-in-test": false,
"no-null-undefined-union": false,
"invalid-void": false
}
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@tsconfig/recommended",
"include": ["./src"]
}

0 comments on commit 46daf4c

Please sign in to comment.