diff --git a/1-easy/2-return-type/template.ts b/1-easy/2-return-type/template.ts index e4d54113..74e2a90a 100644 --- a/1-easy/2-return-type/template.ts +++ b/1-easy/2-return-type/template.ts @@ -3,9 +3,18 @@ // type MyReturnType any> = T /* _____________ Test Cases _____________ */ -import { expectType, _ } from '@type-challenges/utils' +import { Equal, Expect } from '@type-challenges/utils' -expectType(_ as MyReturnType<() => string>) -expectType<123>(_ as MyReturnType<() => 123>) -expectType<{a: [12, 'foo']; bar: 'hello'}>(_ as MyReturnType<() => {a: [12, 'foo']; bar: 'hello'}>) -expectType>(_ as MyReturnType<() => Promise>) +type ComplexObject = { + a: [12, 'foo'] + bar: 'hello' + prev(): number +} + +type cases = [ + Expect string>>>, + Expect 123>>>, + Expect ComplexObject>>>, + Expect, MyReturnType<() => Promise>>>, + Expect 'foo', MyReturnType<() => () => 'foo'>>> +] diff --git a/README.md b/README.md index 63607651..6f48aa78 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

-Collection of TypeScript typing challenges
+Collection of TypeScript type challenges
 

@@ -11,6 +11,10 @@ Collection of TypeScript typing challenges ## Intro +

+by the power of TypeScript's well-known Turing Completed type system +

+ > TODO ## Challenges @@ -34,6 +38,7 @@ Collection of TypeScript typing challenges Inspired by / Ported from - [piotrwitek/utility-types](https://github.com/piotrwitek/utility-types) +- [wixplosives/typescript-type-utils](https://github.com/wixplosives/typescript-type-utils) - [psmyrdek/typescript-challenges](https://github.com/psmyrdek/typescript-challenges) Contributors diff --git a/package.json b/package.json index ac3bea6e..c2351ae3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "license": "MIT", "scripts": { "preinstall": "npx only-allow pnpm", - "utils:build": "pnpm -C utils build", "utils:release": "pnpm -C utils release" }, "devDependencies": { @@ -18,6 +17,7 @@ "@types/lz-string": "^1.3.34", "@types/node": "^14.0.24", "@typescript-eslint/eslint-plugin": "^3.7.0", + "@typescript-eslint/parser": "^3.7.0", "eslint": "^7.5.0", "fast-glob": "^3.2.4", "js-yaml": "^3.14.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0c8d696f..4ec040b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,7 +8,8 @@ importers: '@types/js-yaml': 3.12.5 '@types/lz-string': 1.3.34 '@types/node': 14.0.24 - '@typescript-eslint/eslint-plugin': 3.7.0_eslint@7.5.0+typescript@3.9.7 + '@typescript-eslint/eslint-plugin': 3.7.0_a7d792035c43f2b80bcf395c5516fe5c + '@typescript-eslint/parser': 3.7.0_eslint@7.5.0+typescript@3.9.7 eslint: 7.5.0 fast-glob: 3.2.4 js-yaml: 3.14.0 @@ -25,6 +26,7 @@ importers: '@types/lz-string': ^1.3.34 '@types/node': ^14.0.24 '@typescript-eslint/eslint-plugin': ^3.7.0 + '@typescript-eslint/parser': ^3.7.0 eslint: ^7.5.0 fast-glob: ^3.2.4 js-yaml: ^3.14.0 @@ -37,14 +39,8 @@ importers: utility-types: ^3.10.0 utils: devDependencies: - rollup: 2.22.2 - rollup-plugin-dts: 1.4.9_rollup@2.22.2+typescript@3.9.7 - rollup-plugin-typescript2: 0.27.1_rollup@2.22.2+typescript@3.9.7 typescript: 3.9.7 specifiers: - rollup: ^2.22.2 - rollup-plugin-dts: ^1.4.9 - rollup-plugin-typescript2: ^0.27.1 typescript: ^3.9.7 lockfileVersion: 5.1 packages: @@ -254,9 +250,10 @@ packages: optional: true resolution: integrity: sha512-06lfjo76naNeOMDl+mWG9Fh/a0UHKLGhin+mGaIw72FUMbMGBkdi/FEJmgEDzh4eE73KIYzHWvOCYJ0ak7nrJQ== - /@typescript-eslint/eslint-plugin/3.7.0_eslint@7.5.0+typescript@3.9.7: + /@typescript-eslint/eslint-plugin/3.7.0_a7d792035c43f2b80bcf395c5516fe5c: dependencies: '@typescript-eslint/experimental-utils': 3.7.0_eslint@7.5.0+typescript@3.9.7 + '@typescript-eslint/parser': 3.7.0_eslint@7.5.0+typescript@3.9.7 debug: 4.1.1 eslint: 7.5.0 functional-red-black-tree: 1.0.1 diff --git a/tsconfig.base.json b/tsconfig.base.json index 8ed49a2e..5d5d4413 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -7,7 +7,7 @@ "esModuleInterop": true, "moduleResolution": "node", "skipLibCheck": true, - "noUnusedLocals": true, + "noUnusedLocals": false, "noUnusedParameters": true, "noImplicitReturns": true, }, diff --git a/utils/index.d.test.ts b/utils/index.d.test.ts new file mode 100644 index 00000000..ad410173 --- /dev/null +++ b/utils/index.d.test.ts @@ -0,0 +1,18 @@ +import { Equal, Expect, NotEqual } from './index' + +type cases = [ + Expect>, + + // @ts-expect-error + Expect>, + + Expect>, + + // @ts-expect-error + Expect>, + + Expect>, + + // @ts-expect-error + Expect>, +] diff --git a/utils/index.d.ts b/utils/index.d.ts new file mode 100644 index 00000000..0a42e71f --- /dev/null +++ b/utils/index.d.ts @@ -0,0 +1,19 @@ +type NOT_EQUAL_INTERNAL = UnionToIntersection extends UnionToIntersection + ? UnionToIntersection extends UnionToIntersection + ? false + : true + : true + +export type Expect = T +export type ExpectTrue = T +export type ExpectFalse = T + +export type NotEqual = true extends NOT_EQUAL_INTERNAL ? true : false +export type Equal = NotEqual extends false ? true : false + +export type ExpectExtends = EXPECTED extends VALUE ? true : false +export type ExpectValidArgs any, ARGS extends any[]> = ARGS extends Parameters + ? true + : false + +export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never diff --git a/utils/package.json b/utils/package.json index 52c16173..f2f10b0c 100644 --- a/utils/package.json +++ b/utils/package.json @@ -2,22 +2,14 @@ "name": "@type-challenges/utils", "version": "0.0.2-beta.1", "license": "MIT", - "main": "dist/index.js", - "module": "dist/index.esm.js", - "browser": "dist/index.esm.js", - "typing": "dist/index.d.ts", - "types": "dist/index.d.ts", + "types": "index.d.ts", "files": [ - "dist" + "index.d.ts" ], "scripts": { - "build": "rollup -c", - "release": "pnpx bumpp --commit --tag && pnpm build && pnpm publish" + "release": "pnpx bumpp --commit --tag && pnpm publish" }, "devDependencies": { - "rollup": "^2.22.2", - "rollup-plugin-dts": "^1.4.9", - "rollup-plugin-typescript2": "^0.27.1", "typescript": "^3.9.7" } } diff --git a/utils/rollup.config.js b/utils/rollup.config.js deleted file mode 100644 index 76e6d635..00000000 --- a/utils/rollup.config.js +++ /dev/null @@ -1,27 +0,0 @@ -import typescript from 'rollup-plugin-typescript2' -import dts from 'rollup-plugin-dts' - -export default [ - { - input: 'src/index.ts', - output: [ - { - file: 'dist/index.js', - format: 'cjs', - }, - { - file: 'dist/index.esm.js', - format: 'esm', - }, - ], - plugins: [typescript()], - }, - { - input: 'src/index.ts', - output: { - file: 'dist/index.d.ts', - format: 'es', - }, - plugins: [dts()], - }, -] diff --git a/utils/src/index.ts b/utils/src/index.ts deleted file mode 100644 index 1eb2231d..00000000 --- a/utils/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare function expectType(value: T): void -export declare function expectError(value: T): void -export const _: any = undefined \ No newline at end of file