Skip to content

Commit

Permalink
validation: make marker optional (#1690)
Browse files Browse the repository at this point in the history
To make the type checker happy when crating instances of the types.
Currently the following will result in an error (`Type 'string' is not
assignable to type 'string & MinLen<1> & MaxLen<2>'. Type 'string' is
not assignable to type 'MinLen<1>'.`):

```ts
interface MyType {
    field: string & MinLen<1> & MaxLen<2>;
}

const x: MyType = { field: "a" };
```
  • Loading branch information
fredr authored Jan 8, 2025
1 parent c16172b commit 7fedc34
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions runtimes/js/encore.dev/validate/mod.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
declare const __validate: unique symbol;

export type Min<N extends number> = {
[__validate]: {
[__validate]?: {
minValue: N;
};
};

export type Max<N extends number> = {
[__validate]: {
[__validate]?: {
maxValue: N;
};
};

export type MinLen<N extends number> = {
[__validate]: {
[__validate]?: {
minLen: N;
};
};

export type MaxLen<N extends number> = {
[__validate]: {
[__validate]?: {
maxLen: N;
};
};

export type MatchesRegexp<S extends string> = {
[__validate]: {
[__validate]?: {
matchesRegexp: S;
};
};

export type StartsWith<S extends string> = {
[__validate]: {
[__validate]?: {
startsWith: S;
};
};

export type EndsWith<S extends string> = {
[__validate]: {
[__validate]?: {
endsWith: S;
};
};

export type IsEmail = {
[__validate]: {
[__validate]?: {
isEmail: true;
};
};

export type IsURL = {
[__validate]: {
[__validate]?: {
isURL: true;
};
};

0 comments on commit 7fedc34

Please sign in to comment.