Skip to content

Commit

Permalink
Added types for all primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
taras committed Apr 6, 2019
1 parent b4ac84b commit f896cbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 4 additions & 6 deletions types/microstates.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
declare module 'microstates' {
interface Base {}

interface Constructor<T> {
new (...args: any[]): T;
}

export const Any: Constructor<Any>;
export interface Any {
set(value: any): Any;
Expand Down Expand Up @@ -98,6 +92,10 @@ declare module 'microstates' {
? ObjectDSL<T>
: PrimitiveDSL<T>;

interface Constructor<T> {
new (...args: any[]): T;
}

export function from<T>(value?: T): DSL<T> & Any;

export function create<T>(Type: Constructor<T>, value?: any): T & Any;
Expand Down
9 changes: 9 additions & 0 deletions types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ describe('from', () => {
});
expectType<ObjectType<ArrayType<BooleanType | StringType | NumberType>>>(o);
});

// NOTE: I'm not sure if this is possible
// it('returns an ArrayType<ObjectType<NumberType>> when passed an array of objects with number values', () => {
// let a = from([
// { a: 42 }, { b: 2 }
// ]);
// expectType<ArrayType<ObjectType<NumberType>>>(a);
// });

// NOTE: this is not possible because TypeScript doesn't support recursive types
// it('returns an ObjectType<ObjectType<Number>> when passed an object containing numbers', () => {
// let o = from({
Expand Down

0 comments on commit f896cbf

Please sign in to comment.