Skip to content

Commit

Permalink
test: add typescript satisfies fixture (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabinmarcu authored Mar 6, 2023
1 parent 72510e7 commit 838bf9a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,12 @@ Decorator called with 1 arguments.
file: '<cwd>/test.ts',
dir: '<cwd>',
resolve: '<cwd>/test.ts'
} undefined [class DecoratedClass]"
} undefined [class DecoratedClass]
{
satisfiesTest: {
firstTest: { name: 'first', avatar: 'https://example.com/first.png' },
secondTest: { name: 'second', avatar: [Object] },
normalizeUserEntity: [Function: normalizeUserEntity]
}
}"
`;
3 changes: 3 additions & 0 deletions test/fixtures/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import test, { FeedService } from "./test";
import Clazz from "./decorators";
import { test as satisfiesTest } from "./satisfies";

export type { Test } from "./types";

console.log(test(), FeedService, Clazz);
console.log(satisfiesTest());
52 changes: 52 additions & 0 deletions test/fixtures/typescript/satisfies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
type ImageType = {
src: string;
width: number;
height: number;
};

interface User {
name: string;
avatar: string | ImageType;
}

interface NormalizedUser extends User {
avatar: ImageType;
}

interface UserNormalizer {
(user: User): NormalizedUser;
}

export const firstTest = {
name: "first",
avatar: "https://example.com/first.png",
} satisfies User;

export const secondTest = {
name: "second",
avatar: {
src: "https://example.com/second.png",
width: 100,
height: 100,
},
} satisfies User;

export const normalizeUserEntity = (({ name, avatar }: User) =>
({
name,
avatar: {
src: typeof avatar === "string" ? avatar : avatar.src,
width: 100,
height: 100,
},
} satisfies NormalizedUser)) satisfies UserNormalizer;

export const test = () => {
return {
satisfiesTest: {
firstTest,
secondTest,
normalizeUserEntity,
},
};
};

0 comments on commit 838bf9a

Please sign in to comment.