Skip to content
Open
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
3 changes: 2 additions & 1 deletion sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function isLiteral(expected: null): StrictValidator<unknown, null>;
export function isLiteral(expected: true): StrictValidator<unknown, true>;
export function isLiteral(expected: false): StrictValidator<unknown, false>;
export function isLiteral<T extends number>(expected: T): StrictValidator<unknown, T>;
export function isLiteral<T extends bigint>(expected: T): StrictValidator<unknown, T>;
export function isLiteral<T extends string>(expected: T): StrictValidator<unknown, T>;
export function isLiteral<T>(expected: T): StrictValidator<unknown, T>;
export function isLiteral<T>(expected: T) {
Expand Down Expand Up @@ -732,7 +733,7 @@ export const hasKeyRelationship = (subject: string, relationship: KeyRelationshi

if (problems.length >= 1)
return pushError(state, `Property "${subject}" ${spec.message} ${plural(problems.length, `property`, `properties`)} ${problems.map(name => `"${name}"`).join(`, `)}`);

return true;
},
})
Expand Down
6 changes: 6 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "es2020"
}
}
4 changes: 4 additions & 0 deletions tests/type-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import * as t from '../sources';
if (t.isLiteral(42)(foo)) {
const bar: 42 = foo;
}

Copy link
Owner

Choose a reason for hiding this comment

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

Any way to remove the messages at the top? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 I tried using a nested tsconfig.json, but it only gets rid of the editor warning, so it's still present if type-checking from the root. Maybe some magic with project references? Or should we just add a @ts-expect-error to the line above?

Copy link
Owner

Choose a reason for hiding this comment

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

I think the best is to use ES2020 in the general tsconfig.json, and create a tsconfig.build.json that extends the main one but downgrades the target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like we can't set ES2020 as the target for development, as TS won't transpile optional chaining anymore, which isn't supported by Node 12.

if (t.isLiteral(42n)(foo)) {
const bar: 42n = foo;
}
}

(foo: unknown) => {
Expand Down