Skip to content

Commit

Permalink
✨ 🚨 expect の引数と戻り値の型パラメーターTを連携
Browse files Browse the repository at this point in the history
しかし、ビルドするとエラーに。

$ npm run build

> [email protected] build
> run-s compile lint

> [email protected] compile
> tsc

src/assertions/expect.ts:41:14 - error TS4023: Exported variable 'expect' has or is using name 'APIResponseAssertions' from external module "/Users/takeshi/groovenauts/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

41 export const expect = expectBody;
                ~~~~~~

src/assertions/expect.ts:41:14 - error TS4023: Exported variable 'expect' has or is using name 'GenericAssertions' from external module "/Users/takeshi/groovenauts/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

41 export const expect = expectBody;
                ~~~~~~

src/assertions/expect.ts:41:14 - error TS4023: Exported variable 'expect' has or is using name 'LocatorAssertions' from external module "/Users/takeshi/groovenauts/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

41 export const expect = expectBody;
                ~~~~~~

src/assertions/expect.ts:41:14 - error TS4023: Exported variable 'expect' has or is using name 'PageAssertions' from external module "/Users/takeshi/groovenauts/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

41 export const expect = expectBody;
                ~~~~~~

src/assertions/expect.ts:41:14 - error TS4023: Exported variable 'expect' has or is using name 'SnapshotAssertions' from external module "/Users/takeshi/groovenauts/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

41 export const expect = expectBody;
                ~~~~~~

src/assertions/expect.ts:41:14 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

41 export const expect = expectBody;
                ~~~~~~

Found 6 errors in the same file, starting at: src/assertions/expect.ts:41

ERROR: "compile" exited with 1.
  • Loading branch information
akm committed Jan 2, 2024
1 parent 5c002df commit 3c11fc3
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/assertions/expect.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {expect as origExpect} from '@playwright/test';
import {Locator, expect as origExpect} from '@playwright/test';
import {Displayable} from '../materials/Displayable';

type ExpectReturnType = ReturnType<typeof origExpect>;
type ExpectReturnType<T> = ReturnType<typeof origExpect<T>>;
type SoftType = typeof origExpect.soft;
type ConfigureType = typeof origExpect.configure;
type PollType = typeof origExpect.poll;
type ExtendType = typeof origExpect.extend;

export type ExpectType = {
(
x: unknown,
<T>(
x: T,
messageOrOptions?: string | {message?: string}
): ExpectReturnType;
): ExpectReturnType<T>;

// These methods are experimental
// See https://playwright.dev/docs/test-assertions#negating-matchers for more detail
Expand All @@ -21,20 +21,21 @@ export type ExpectType = {
extend: ExtendType;
};

export const expect = ((): ExpectType => {
const body = (
x: unknown,
messageOrOptions?: string | {message?: string}
): ExpectReturnType => {
return origExpect(
x instanceof Displayable ? x._locator : x,
messageOrOptions
);
};
return Object.assign(body, {
soft: origExpect.soft.bind(body),
configure: origExpect.configure.bind(body),
poll: origExpect.poll.bind(body),
extend: origExpect.extend.bind(body),
});
})();
const expectBody = <T>(
x: T,
messageOrOptions?: string | {message?: string}
): ExpectReturnType<T | Locator> => {
return origExpect(
x instanceof Displayable ? x._locator : x,
messageOrOptions
);
};

// export const expect = Object.assign(expectBody, {
// soft: origExpect.soft.bind(expectBody),
// configure: origExpect.configure.bind(expectBody),
// poll: origExpect.poll.bind(expectBody),
// extend: origExpect.extend.bind(expectBody),
// });

export const expect = expectBody;

Check failure on line 41 in src/assertions/expect.ts

View workflow job for this annotation

GitHub Actions / build

Exported variable 'expect' has or is using name 'APIResponseAssertions' from external module "/home/runner/work/playwright-pom-materials/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

Check failure on line 41 in src/assertions/expect.ts

View workflow job for this annotation

GitHub Actions / build

Exported variable 'expect' has or is using name 'GenericAssertions' from external module "/home/runner/work/playwright-pom-materials/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

Check failure on line 41 in src/assertions/expect.ts

View workflow job for this annotation

GitHub Actions / build

Exported variable 'expect' has or is using name 'LocatorAssertions' from external module "/home/runner/work/playwright-pom-materials/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

Check failure on line 41 in src/assertions/expect.ts

View workflow job for this annotation

GitHub Actions / build

Exported variable 'expect' has or is using name 'PageAssertions' from external module "/home/runner/work/playwright-pom-materials/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

Check failure on line 41 in src/assertions/expect.ts

View workflow job for this annotation

GitHub Actions / build

Exported variable 'expect' has or is using name 'SnapshotAssertions' from external module "/home/runner/work/playwright-pom-materials/playwright-pom-materials/node_modules/playwright/types/test" but cannot be named.

Check failure on line 41 in src/assertions/expect.ts

View workflow job for this annotation

GitHub Actions / build

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

0 comments on commit 3c11fc3

Please sign in to comment.