-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
bb05b2a
commit 10237a8
Showing
14 changed files
with
435 additions
and
90 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
20 changes: 20 additions & 0 deletions
20
test/fixtures/tstyche/documentation/__typetests__/docs.tst.ts
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,20 @@ | ||
import { expect, test } from "tstyche"; | ||
|
||
function firstItem<T>(target: Array<T>): T | undefined { | ||
return target[0]; | ||
} | ||
|
||
test("first item requires a parameter", () => { | ||
expect(firstItem(["a", "b", "c"])).type.toBe<string | undefined>(); | ||
|
||
// @ts-expect-error | ||
expect(firstItem()).type.toRaiseError("Expected 1 argument"); | ||
}); | ||
|
||
function secondItem<T>(target: Array<T>): T | undefined { | ||
return target[1]; | ||
} | ||
|
||
test("handles numbers", () => { | ||
expect(secondItem([1, 2, 3])).type.toBe<number | undefined>(); | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/fixtures/tstyche/documentation/__typetests__/tsconfig.json
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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"types": [] | ||
}, | ||
"include": ["./"], | ||
"exclude": [] | ||
} |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": ["./__typetests__"] | ||
} |
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,14 @@ | ||
import { test, expect, describe } from 'tstyche' | ||
import type { MethodLikeKeys } from '../fire.js' | ||
|
||
interface Sample { | ||
description: string | ||
getLength: () => number | ||
getWidth?: () => number | ||
} | ||
|
||
describe('fire', () => { | ||
test('all method keys are found', () => { | ||
expect<MethodLikeKeys<Sample>>().type.toBe<'getLength' | 'getWidth'>() | ||
}) | ||
}) |
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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"types": [] | ||
}, | ||
"include": ["./"], | ||
"exclude": [] | ||
} |
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,5 @@ | ||
type MethodLike = (...args: any) => any; | ||
|
||
export type MethodLikeKeys<T> = keyof { | ||
[K in keyof T as T[K] extends MethodLike ? K : never]: T[K]; | ||
}; |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": ["./__typetests__"] | ||
} |
14 changes: 14 additions & 0 deletions
14
test/fixtures/tstyche/firefought/__typetests__/fire.tst.ts
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,14 @@ | ||
import { describe, test, expect } from "tstyche"; | ||
import type { MethodLikeKeys } from "../fire.js"; | ||
|
||
interface Sample { | ||
description: string; | ||
getLength: () => number; | ||
getWidth?: () => number; | ||
} | ||
|
||
describe('fire', () => { | ||
test('all method keys are found', () => { | ||
expect<MethodLikeKeys<Sample>>().type.toBe<"getLength" | "getWidth">(); | ||
}) | ||
}) |
10 changes: 10 additions & 0 deletions
10
test/fixtures/tstyche/firefought/__typetests__/tsconfig.json
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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"types": [] | ||
}, | ||
"include": ["./"], | ||
"exclude": [] | ||
} |
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,5 @@ | ||
type MethodLike = (...args: any) => any; | ||
|
||
export type MethodLikeKeys<T> = keyof { | ||
[K in keyof T as Required<T>[K] extends MethodLike ? K : never]: T[K]; | ||
}; |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": ["./__typetests__"] | ||
} |
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