Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add typescript satisfies fixture #107

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
};
};