Skip to content

Commit

Permalink
build: πŸ“¦ prettier for new TS version πŸ’… (#269)
Browse files Browse the repository at this point in the history
* build: πŸ“¦ use typescript@^4.1.0

* build: πŸ“¦ prettier@^2.0.0

* fix: πŸ”„ run test:fix

* fix: πŸ§ͺ run test:fix
  • Loading branch information
Beraliv committed Nov 8, 2021
1 parent 98e4c7a commit 6367fb9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions example/types.ts
Expand Up @@ -68,15 +68,15 @@ function makePositiveNumber(n: number): PositiveNumber {
if (n <= 0) {
throw new Error(`Value ${n} is not positive !`);
}
return (n as any) as PositiveNumber; // this ugly cast is required but only when "producing" opaque types
return n as any as PositiveNumber; // this ugly cast is required but only when "producing" opaque types
}

type NegativeNumber = Opaque<number, "NegativeNumber">;
function makeNegativeNumber(n: number): NegativeNumber {
if (n >= 0) {
throw new Error(`Value ${n} is not negative !`);
}
return (n as any) as NegativeNumber; // this ugly cast is required but only when "producing" opaque types
return n as any as NegativeNumber; // this ugly cast is required but only when "producing" opaque types
}

let a = makePositiveNumber(5); // runtime check
Expand Down
8 changes: 5 additions & 3 deletions lib/functions.ts
Expand Up @@ -14,6 +14,8 @@ export function assert(condition: any, msg: string = "no additional info provide

export function noop(..._args: unknown[]): void {}

export const isExact = <ExpectedShape>() => <ActualShape>(x: Exact<ActualShape, ExpectedShape>): ExpectedShape => {
return x;
};
export const isExact =
<ExpectedShape>() =>
<ActualShape>(x: Exact<ActualShape, ExpectedShape>): ExpectedShape => {
return x;
};
25 changes: 11 additions & 14 deletions lib/types.ts
Expand Up @@ -260,19 +260,16 @@ export type DeepOmit<T extends DeepOmitModify<Filter>, Filter> = T extends Built
? ItemType extends DeepOmitModify<Filter>
? Promise<DeepOmit<ItemType, Filter>>
: T
: { [K in Exclude<OptionalKeys<T>, keyof Filter>]+?: T[K] } &
OmitProperties<
{
[K in Extract<OptionalKeys<T>, keyof Filter>]+?: Filter[K] extends true
? never
: T[K] extends DeepOmitModify<Filter[K]>
? DeepOmit<T[K], Filter[K]>
: T[K];
},
never
> &
{ [K in Exclude<RequiredKeys<T>, keyof Filter>]: T[K] } &
OmitProperties<
: { [K in Exclude<OptionalKeys<T>, keyof Filter>]+?: T[K] } & OmitProperties<
{
[K in Extract<OptionalKeys<T>, keyof Filter>]+?: Filter[K] extends true
? never
: T[K] extends DeepOmitModify<Filter[K]>
? DeepOmit<T[K], Filter[K]>
: T[K];
},
never
> & { [K in Exclude<RequiredKeys<T>, keyof Filter>]: T[K] } & OmitProperties<
{
[K in Extract<RequiredKeys<T>, keyof Filter>]: Filter[K] extends true
? never
Expand Down Expand Up @@ -302,7 +299,7 @@ export type NonEmptyObject<T extends {}> = keyof T extends never ? never : T;
/** Merge 2 types, properties types from the latter override the ones defined on the former type */
export type Merge<M, N> = Omit<M, keyof N> & N;

type _MergeN<T extends readonly any[], Result> = T extends readonly [infer Head, ...(infer Tail)]
type _MergeN<T extends readonly any[], Result> = T extends readonly [infer Head, ...infer Tail]
? _MergeN<Tail, Merge<Result, Head>>
: Result;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -37,7 +37,7 @@
"@codechecks/build-size-watcher": "^0.1.0",
"@codechecks/client": "^0.1.11",
"conditional-type-checks": "^1.0.4",
"prettier": "^1.19.1",
"prettier": "^2.0.0",
"rimraf": "^3.0.2",
"typescript": "^4.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.ts
Expand Up @@ -1154,7 +1154,7 @@ function testWritableKeys() {
function testAssert() {
type TestType1 = string | undefined;
type Expected = string;
const anything = (undefined as any) as TestType1;
const anything = undefined as any as TestType1;

assert(anything);
type Actual = typeof anything;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -1629,6 +1629,11 @@ prettier@^1.19.1:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

prettier@^2.0.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.4.1.tgz#671e11c89c14a4cfc876ce564106c4a6726c9f5c"
integrity sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==

promise@^8.0.2:
version "8.0.3"
resolved "https://registry.yarnpkg.com/promise/-/promise-8.0.3.tgz#f592e099c6cddc000d538ee7283bb190452b0bf6"
Expand Down

0 comments on commit 6367fb9

Please sign in to comment.