Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions .github/workflows/web_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ on:
push:
branches: [ main ]
paths:
- 'renderers/web_core/**/*'
- 'renderers/web_core/**'
- '.github/workflows/web_build_and_test.yml'
pull_request:
paths:
- 'renderers/web_core/**/*'
- 'renderers/web_core/**'
- '.github/workflows/web_build_and_test.yml'

jobs:
Expand All @@ -49,6 +49,8 @@ jobs:
working-directory: ./renderers/web_core
run: npm run test
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

Expand Down
4 changes: 2 additions & 2 deletions renderers/web_core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion renderers/web_core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"clean": "if-file-deleted"
},
"test": {
"command": "node --test dist",
"command": "node --test \"dist/**/*.test.js\"",
"dependencies": [
"build"
]
Expand Down
6 changes: 4 additions & 2 deletions renderers/web_core/src/v0_9/catalog/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ describe('InferredComponentApiSchemaType', () => {
name: 'MockComp',
schema: mockSchema,
} satisfies ComponentApi;
// Appease typescript-eslint/no-unused-vars
type _ = typeof mockApi;

assert.ok(mockApi);

// Type-level equivalence assertion using z.infer
type ExpectedType = z.infer<typeof mockSchema>;
Expand All @@ -120,6 +120,7 @@ describe('InferredComponentApiSchemaType', () => {
// This happens when `mockApi: ComponentApi`, but doesn't when
// `mockApi {} satisfies ComponentApi`!
const inferredIsAny: IsAny<InferredType> = false;
assert.strictEqual(inferredIsAny, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While using assert.strictEqual works to silence the 'no-unused-vars' lint error, it adds a runtime assertion for what is a compile-time type check. The purpose of inferredIsAny is to fail at compile time if the type is incorrect, not to be asserted at runtime.

A more idiomatic and clearer way to mark a variable as intentionally used for its type-level effects is to use the void operator. This signals that you are using the variable for its compile-time check and intentionally discarding its value, without adding a runtime assertion.

Suggested change
assert.strictEqual(inferredIsAny, false);
void inferredIsAny;


// When types are not "any", check that they're the same by checking if they
// extend each other.
Expand All @@ -132,5 +133,6 @@ describe('InferredComponentApiSchemaType', () => {
// typesMatchExact only accepts "true" if `TypesAreEquivalent`
const typesMatchExact: TypesAreEquivalent<ExpectedType, InferredType> =
true;
assert.strictEqual(typesMatchExact, true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the other type-level check, using assert.strictEqual here adds a runtime assertion for a compile-time check.

To make the intent clearer and avoid a redundant runtime check, you can use the void operator to mark typesMatchExact as intentionally used for its type-level effects.

Suggested change
assert.strictEqual(typesMatchExact, true);
void typesMatchExact;

});
});
Loading