-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
245 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,14 @@ | ||
import { string } from './schema' | ||
import { func, object, string } from './schema' | ||
import type { Infer, Type } from './schema' | ||
|
||
// see https://github.com/colinhacks/zod?tab=readme-ov-file#functions | ||
|
||
describe('rpc.spec', () => { | ||
it('should do something', async () => { | ||
const rpcSchema = { | ||
echo: string(), | ||
} | ||
|
||
type RpcRaw = typeof rpcSchema | ||
|
||
type RpcFunc<T> = { | ||
[K in keyof T]: (arg: Infer<T[K]>) => void | ||
} | ||
|
||
type Rpc = RpcFunc<RpcRaw> | ||
}) | ||
|
||
it('should do something2', async () => { | ||
function func(args: Type<any>[], result?: Type<any>) { | ||
return { | ||
args, | ||
result, | ||
} | ||
} | ||
|
||
const rpcSchema = { | ||
const rpcSchema = object({ | ||
echo: func([string()], string()), | ||
} | ||
|
||
type RpcRaw = typeof rpcSchema | ||
|
||
type RpcFunc<T> = { | ||
[K in keyof T]: (arg: Infer<T[K]>) => void | ||
} | ||
}) | ||
|
||
type Rpc = RpcFunc<RpcRaw> | ||
type RpcRaw = Infer<typeof rpcSchema> | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class TypeClass<T = unknown> { | ||
optional(): TypeClass<T | undefined> { | ||
return this | ||
} | ||
} | ||
|
||
class TypeStringClass<T extends string> extends TypeClass<T> { | ||
|
||
} | ||
|
||
const o = new TypeStringClass() | ||
const v = o.optional() | ||
type t = typeof v // expect: TypeStringClass<string | undefined> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable ts/no-unsafe-declaration-merging */ | ||
// // Define an interface for the instance type | ||
// interface MyTypeInstance { | ||
// value: number | ||
// test: () => number | ||
// } | ||
|
||
// // Constructor function | ||
// function MyType(this: MyTypeInstance, value: number) { | ||
// this.value = value | ||
// } | ||
|
||
// MyType.prototype.test = function () { | ||
// return this.value | ||
// } | ||
|
||
class MyType { | ||
value: number | ||
constructor(value: number) { | ||
this.value = value | ||
} | ||
} | ||
|
||
interface MyType { | ||
test: () => number | ||
} | ||
|
||
describe('sandbox.spec', () => { | ||
it('should do something', async () => { | ||
// Create an instance of MyType using the 'new' keyword | ||
const my = new MyType(123) | ||
|
||
MyType.prototype.test = function () { | ||
return this.value + 1 | ||
} | ||
|
||
// Example usage | ||
expect(my.test()).toMatchInlineSnapshot(`124`) | ||
expect(my).toMatchInlineSnapshot(` | ||
MyType { | ||
"value": 123, | ||
} | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.