Connect, collaborate, and grow with a community of TypeScript developers
change test types and ingest script (#906)
bautistaaa4f146ab17558
diff --git a/challenges/blank/tests.ts b/challenges/blank/tests.tsindex 78123de9..e69de29b 100644--- a/challenges/blank/tests.ts+++ b/challenges/blank/tests.ts@@ -1 +0,0 @@-import { Expect, Equal } from 'type-testing';diff --git a/challenges/generic-type-arguments/tests.ts b/challenges/generic-type-arguments/tests.tsindex b790e5ce..5bf77529 100644--- a/challenges/generic-type-arguments/tests.ts+++ b/challenges/generic-type-arguments/tests.ts@@ -1,5 +1,3 @@-import { Expect, Equal } from 'type-testing';-type test_CapreseSaladName = Expect<Equal<CapreseSalad['name'],'Caprese Salad'diff --git a/challenges/generic-type-constraints/tests.ts b/challenges/generic-type-constraints/tests.tsindex a3fb7e8f..9f93b748 100644--- a/challenges/generic-type-constraints/tests.ts+++ b/challenges/generic-type-constraints/tests.ts@@ -1,5 +1,3 @@-import { Expect, Equal } from 'type-testing';-type test_AllowStringString = Expect<Equal<AllowString<string>,string@@ -39,4 +37,4 @@ type error_CreateLoggerStringArg =type error_CreateLoggerTwoArgs =// @ts-expect-error invalid input- CreateLogger<(a: number, b: number) => void>;\ No newline at end of file+ CreateLogger<(a: number, b: number) => void>;diff --git a/challenges/indexed-types/tests.ts b/challenges/indexed-types/tests.tsindex 987a22d4..1fcc3e6b 100644--- a/challenges/indexed-types/tests.ts+++ b/challenges/indexed-types/tests.ts@@ -1,5 +1,3 @@-import { Expect, Equal } from 'type-testing';-type Cars = ["Bugatti", "Ferarri", "Lambo", "Porsche", "Toyota Corolla"]type Donations = {diff --git a/challenges/literal-types/tests.ts b/challenges/literal-types/tests.tsindex 4eaf7b94..0bc549d8 100644--- a/challenges/literal-types/tests.ts+++ b/challenges/literal-types/tests.ts@@ -1,5 +1,3 @@-import { Expect, Equal } from 'type-testing';-type test_LiteralString = Expect<Equal<LiteralString,'chocolate chips'diff --git a/challenges/primitive-data-types/tests.ts b/challenges/primitive-data-types/tests.tsindex 7d2b6da5..299794c6 100644--- a/challenges/primitive-data-types/tests.ts+++ b/challenges/primitive-data-types/tests.ts@@ -1,5 +1,3 @@-import { Expect } from 'type-testing';-type test_age = Expect<NotLiteral<number, typeof age>>;type test_name = Expect<NotLiteral<string, typeof name>>;@@ -7,4 +5,4 @@ type test_name = Expect<NotLiteral<string, typeof name>>;type NotLiteral<T, U> =1 extends (T extends U ? U extends T ? 1 : 2 : 3)? true- : false\ No newline at end of file+ : falsediff --git a/challenges/type-aliases/tests.ts b/challenges/type-aliases/tests.tsindex f8b59d63..dee4867d 100644--- a/challenges/type-aliases/tests.ts+++ b/challenges/type-aliases/tests.ts@@ -1,5 +1,3 @@-import { Expect, Equal } from 'type-testing';-type test_Name = Expect<Equal<Name, string>>;type test_Year = Expect<Equal<Year, number>>;type test_Count = Expect<Equal<Count, number>>;@@ -41,4 +39,4 @@ const voyager1 = {{ name: "Golden Record", mass: 0.3 },{ name: "Instruments", mass: 721 },],-} satisfies Spacecraft;\ No newline at end of file+} satisfies Spacecraft;diff --git a/challenges/type-unions/tests.ts b/challenges/type-unions/tests.tsindex 9aa181de..d044a076 100644--- a/challenges/type-unions/tests.ts+++ b/challenges/type-unions/tests.ts@@ -1,63 +1,63 @@-import { Expect } from 'type-testing';-import { expect } from 'jest';--const getDistanceInMeters = (distance: Distance) => {- switch (distance.unit) {- case 'miles':- return {- unit: 'meters',- value: distance.value / 1609.34,- } satisfies Meters;-- case 'meters':- return {- unit: 'meters',- value: distance.value,- } satisfies Meters;-- case 'feet':- return {- unit: 'meters',- value: distance.value * 3.28084,- } satisfies Meters;-- default:- // @ts-expect-error (in production codebases, we'd assert an unreachable case here but that's beyond the scope of this lesson)- throw new Error(`unrecognized unit: ${distance.unit}`)- }-}--const lowMarsOrbit = {- unit: 'meters',- value: 300_000-} satisfies Meters;--const mediumMarsOrbit = {- unit: 'meters',- value: 2_000_000-} satisfies Meters;--const highMarsOrbit = {- unit: 'meters',- value: 5_000_000-} satisfies Meters;---expect(getDistanceInMeters({- unit: 'miles',- value: 186.41182099494205,-})).toEqual(lowMarsOrbit);--expect(getDistanceInMeters({- unit: 'meters',- value: 2_000_000,-})).toEqual(mediumMarsOrbit);--expect(getDistanceInMeters({- unit: 'feet',- value: 1523999.9512320017,-})).toEqual(highMarsOrbit);-+// import { Expect } from 'type-testing';+// import { expect } from 'jest';+//+// const getDistanceInMeters = (distance: Distance) => {+// switch (distance.unit) {+// case 'miles':+// return {+// unit: 'meters',+// value: distance.value / 1609.34,+// } satisfies Meters;+//+// case 'meters':+// return {+// unit: 'meters',+// value: distance.value,+// } satisfies Meters;+//+// case 'feet':+// return {+// unit: 'meters',+// value: distance.value * 3.28084,+// } satisfies Meters;+//+// default:+// // @ts-expect-error (in production codebases, we'd assert an unreachable case here but that's beyond the scope of this lesson)+// throw new Error(`unrecognized unit: ${distance.unit}`)+// }+// }+//+// const lowMarsOrbit = {+// unit: 'meters',+// value: 300_000+// } satisfies Meters;+//+// const mediumMarsOrbit = {+// unit: 'meters',+// value: 2_000_000+// } satisfies Meters;+//+// const highMarsOrbit = {+// unit: 'meters',+// value: 5_000_000+// } satisfies Meters;+//+//+// expect(getDistanceInMeters({+// unit: 'miles',+// value: 186.41182099494205,+// })).toEqual(lowMarsOrbit);+//+// expect(getDistanceInMeters({+// unit: 'meters',+// value: 2_000_000,+// })).toEqual(mediumMarsOrbit);+//+// expect(getDistanceInMeters({+// unit: 'feet',+// value: 1523999.9512320017,+// })).toEqual(highMarsOrbit);+///////////////////////////////////////////////////// Part 2@@ -103,7 +103,7 @@ const positionElement = (position: Position): AbsolutePosition => {}}-type Extends<T, U> = T extends U ? true : false;+type Extends<T, U> = T extends U ? true : false;type test_topLeft = Expect<Extends<'topLeft', Position>>;type test_top = Expect<Extends<'top', Position>>;diff --git a/challenges/typeof/tests.ts b/challenges/typeof/tests.tsindex 28a0feda..24c1e3bb 100644--- a/challenges/typeof/tests.ts+++ b/challenges/typeof/tests.ts@@ -1,5 +1,3 @@-import { Expect, Equal } from 'type-testing';-const height = 500;const width = 700;diff --git a/packages/db/seed/data/challenge-ingest.ts b/packages/db/seed/data/challenge-ingest.tsindex 46bba8ad..ae4a1e5d 100644--- a/packages/db/seed/data/challenge-ingest.ts+++ b/packages/db/seed/data/challenge-ingest.ts@@ -10,7 +10,11 @@ export async function ingestChallenges(challengePath: string) {for (const item of items) {const itemPath = path.join(challengePath, item);- if (itemPath.includes('blank') || itemPath.includes('solutions')) {+ if (+ itemPath.includes('blank') ||+ itemPath.includes('solutions') ||+ itemPath.includes('type-unions')+ ) {continue;}diff --git a/packages/monaco/src/editor-types.ts b/packages/monaco/src/editor-types.tsindex 70e17519..b12e0243 100644--- a/packages/monaco/src/editor-types.ts+++ b/packages/monaco/src/editor-types.ts@@ -4,92 +4,61 @@* based on: https://github.com/type-challenges/type-challenges/blob/main/utils/index.d.ts*/export const libSource = `-type Expect<T extends true> = T;-type ExpectTrue<T extends true> = T;-type ExpectFalse<T extends false> = T;-type IsTrue<T extends true> = T;-type IsFalse<T extends false> = T;--type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;-type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y- ? 1- : 2- ? true+type Equal<X, Y> =+ (<T>() => T extends X ? 1 : 2) extends+ (<T>() => T extends Y ? 1 : 2) ? true : false;+type Expect<T extends true> = Equal<T, true>;+type ExpectFalse<T extends false> = Equal<T, false>;+type FalseCases<T extends readonly false[]> =+ Equal<T[number], false> extends true+ ? IsTuple<T> extends true+ ? true+ : false: false;--type IsAny<T> = 0 extends 1 & T ? true : false;-type NotAny<T> = true extends IsAny<T> ? false : true;--type Debug<T> = { [K in keyof T]: T[K] };-type MergeInsertions<T> = T extends object- ? { [K in keyof T]: MergeInsertions<T[K]> }- : T;--type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;--type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false;-type ExpectValidArgs<- FUNC extends (...args: any[]) => any,- ARGS extends any[]-> = ARGS extends Parameters<FUNC> ? true : false;--type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (- k: infer I-) => void- ? I- : never;--type NoInfer<T> = [T][T extends any ? 0 : never];--type IsUnion<T, U = T> = [T] extends [never]+type IsAny<T> = 0 extends (1 & T) ? true : false;+type IsNever<T> = [T] extends [never] ? true : false;+type IsTuple<T> =+ IsNever<T> extends true? false- : T extends unknown- ? [U] extends [T]+ : T extends readonly unknown[]+ ? number extends T["length"]+ ? false+ : true+ : false+;+type IsTuple<T> =+ IsNever<T> extends true+ ? false+ : T extends readonly unknown[]+ ? number extends T["length"]+ ? false+ : true+ : false+;+type IsUnionInternal<T, Copy = T> =+ [T] extends [never] // IsNever check? false- : true+ : T extends never // force distributivity+ ? false+ : [Copy] extends [T] // distributed union equality check+ ? false+ : true+;+type IsUnknown<T> =+ [unknown] extends [T]+ ? IsAny<T> extends true+ ? false+ : IsNever<T> extends true+ ? false+ : true: false;--declare function id<T>(): T;--/**- * Helper function to test your code.- *- * Checks if two types have all the same properties and modifiers- *- * To check what it is failing, you can hover over \`Equal\` and see what the types failing are- */-declare function Equal<A, B>(- ...args: [- ...([a: A, b: B] | []),- ...(Alike<A, B> extends true ? [] : [msg: "not equal"])- ]-): void;--/**- * Helper function to test your code.- *- * Checks that two types aren't the same- *- * To check what it is failing, you can hover over \`NotEqual\` and see what the types failing are- */-declare function NotEqual<A, B>(- ...args: [- ...([a: A, b: B] | []),- ...(Alike<A, B> extends true ? [msg: "equal"] : [])- ]-): void;--/**- * Helper function to test your code.- *- * Checks if type \`A\` extends \`B\`- *- * To check what it is failing, you can hover over \`Extends\` and see what the types failing are- */-declare function Extends<A, B>(- ...args: [- ...([a: A, b: B] | []),- ...([A] extends [B] ? [] : [msg: [A, "doesn't extend", B]])- ]-): void;+type NotEqual<X, Y> =+ (<T>() => T extends X ? 1 : 2) extends+ (<T>() => T extends Y ? 1 : 2) ? false : true;+type TrueCases<T extends readonly true[]> =+ false extends Equal<T[number], true>+ ? false extends IsTuple<T>+ ? false+ : true+ : true;`;