feat: get step one working

This commit is contained in:
Glen Whitney 2022-09-07 02:06:13 -04:00
parent 5618725276
commit 9c36ca3030
4 changed files with 42 additions and 3 deletions

View File

@ -18,5 +18,6 @@
license: 'Apache-2.0', license: 'Apache-2.0',
dependencies: { dependencies: {
'over.ts': 'github:m93a/over.ts', 'over.ts': 'github:m93a/over.ts',
typescript: '^4.8.2',
}, },
} }

View File

@ -2,12 +2,20 @@ lockfileVersion: 5.4
specifiers: specifiers:
over.ts: github:m93a/over.ts over.ts: github:m93a/over.ts
typescript: ^4.8.2
dependencies: dependencies:
over.ts: github.com/m93a/over.ts/0fd6e18afd4ca5a23c9e09d1fcd6b7357b642247 over.ts: github.com/m93a/over.ts/0fd6e18afd4ca5a23c9e09d1fcd6b7357b642247
typescript: 4.8.2
packages: packages:
/typescript/4.8.2:
resolution: {integrity: sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==}
engines: {node: '>=4.2.0'}
hasBin: true
dev: false
github.com/m93a/over.ts/0fd6e18afd4ca5a23c9e09d1fcd6b7357b642247: github.com/m93a/over.ts/0fd6e18afd4ca5a23c9e09d1fcd6b7357b642247:
resolution: {tarball: https://codeload.github.com/m93a/over.ts/tar.gz/0fd6e18afd4ca5a23c9e09d1fcd6b7357b642247} resolution: {tarball: https://codeload.github.com/m93a/over.ts/tar.gz/0fd6e18afd4ca5a23c9e09d1fcd6b7357b642247}
name: over.ts name: over.ts

View File

@ -1,4 +1,4 @@
import { useTypes } from 'over'; import { useTypes } from 'over.ts/src/index';
const types = { const types = {
number: (x: unknown): x is number => typeof x === 'number', number: (x: unknown): x is number => typeof x === 'number',
@ -7,12 +7,26 @@ const types = {
const overload = useTypes(types) const overload = useTypes(types)
const negate = overload({
'number -> number': (a: number): number => {
console.log('Negating number', a)
return -a
},
'bigint -> bigint': (a: bigint): bigint => {
console.log('Negating bigint', a)
return -a
}
})
console.log('Negation of 5 is', negate(5))
console.log('Negation of 5n is', negate(5n))
const add = overload({ const add = overload({
'number,number -> number': (a,b) => { 'number, number -> number': (a: number, b: number): number => {
console.log('Adding numbers', a, b) console.log('Adding numbers', a, b)
return a+b return a+b
}, },
'bigint,bigint -> bigint': (a,b) => { 'bigint, bigint -> bigint': (a: bigint, b: bigint): bigint => {
console.log('Adding bigints', a, b) console.log('Adding bigints', a, b)
return a+b return a+b
} }
@ -20,3 +34,10 @@ const add = overload({
console.log('Sum of 5 and 7 is', add(5,7)) console.log('Sum of 5 and 7 is', add(5,7))
console.log('Sum of 5n and 7n is', add(5n, 7n)) console.log('Sum of 5n and 7n is', add(5n, 7n))
try {
//@ts-expect-error
console.log('Mixed sum is', add(5n, 7))
} catch {
console.log('Mixed sum errored as expected.')
}

9
tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "ES2022",
"moduleResolution": "node"
},
"files": [
"src/steps/one.ts"
]
}