Skip to content

Commit

Permalink
chore: bump prettier version to 3.2.1 and run it (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
noshiro-pf authored Jan 13, 2024
1 parent ac6ac1a commit 77cb852
Show file tree
Hide file tree
Showing 76 changed files with 975 additions and 1,005 deletions.
364 changes: 180 additions & 184 deletions .yarn/releases/yarn-1.18.0.cjs

Large diffs are not rendered by default.

364 changes: 180 additions & 184 deletions .yarn/releases/yarn-1.22.11.cjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions articles/numeric-input-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ type Props = Readonly<{
!Number.isFinite(x)
? p.defaultValue
: x < p.min
? p.min
: p.max < x
? p.max
: ((Math.round(x * 10 ** p.digit) / 10 ** p.digit) as T);
? p.min
: p.max < x
? p.max
: ((Math.round(x * 10 ** p.digit) / 10 ** p.digit) as T);
```

動くコード
Expand Down
15 changes: 8 additions & 7 deletions articles/typescript-branded-type-int.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,14 @@ type ExtractBooleanKeys<B, K extends keyof B> = K extends K

type UnwrapBrandBooleanKey<B> = ExtractBooleanKeys<B, keyof B>;

type GetBrandValuePart<B> = B extends Brand<
infer T,
UnwrapBrandTrueKey<B> & string,
UnwrapBrandFalseKey<B> & string
>
? T
: never;
type GetBrandValuePart<B> =
B extends Brand<
infer T,
UnwrapBrandTrueKey<B> & string,
UnwrapBrandFalseKey<B> & string
>
? T
: never;

/**
* ある key が true | false になる場合、その key を削除する
Expand Down
13 changes: 7 additions & 6 deletions articles/typescript-range-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ console.log(getAllDatesOfMonth(2024, 2));
`RangeList<S, E>` の本体は以下のような実装になります。
```ts
type RangeList<S extends Uint8, E extends Uint8> = BoolOr<
BoolOr<IsNever<S>, IsNever<E>>, // S, E のいずれかが 0 要素の union の場合
BoolOr<IsUnion<S>, IsUnion<E>> // S, E のいずれかが >=2 要素の union の場合
> extends true
? readonly Exclude<LEQ[E], LEQ[Min<S>]>[] // union に対して Seq で型計算すると、結果が正しくないので、その回避のため
: Skip<S, Seq<E>>;
type RangeList<S extends Uint8, E extends Uint8> =
BoolOr<
BoolOr<IsNever<S>, IsNever<E>>, // S, E のいずれかが 0 要素の union の場合
BoolOr<IsUnion<S>, IsUnion<E>> // S, E のいずれかが >=2 要素の union の場合
> extends true
? readonly Exclude<LEQ[E], LEQ[Min<S>]>[] // union に対して Seq で型計算すると、結果が正しくないので、その回避のため
: Skip<S, Seq<E>>;
```
- `Skip<S, Seq<E>>` の部分は `S``E` がちょうど 1 要素の非負整数(0 以上 255 以下)の場合に対応しています
Expand Down
59 changes: 29 additions & 30 deletions articles/typescript-type-utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const expectType = <A, B>(
_relation: TypeEq<A, B> extends true
? '<=' | '='
: TypeExtends<A, B> extends true
? '!=' | '<='
: '!<=' | '!=',
? '!=' | '<='
: '!<=' | '!=',
): void => undefined;
```

Expand Down Expand Up @@ -95,15 +95,15 @@ type BoolAnd<A extends boolean, B extends boolean> =
? TypeEq<B, true> extends true
? true
: TypeEq<B, false> extends true
? false
: never
? false
: never
: TypeEq<A, false> extends true
? TypeEq<B, true> extends true
? false
: TypeEq<B, false> extends true
? false
: never
: never;
? TypeEq<B, true> extends true
? false
: TypeEq<B, false> extends true
? false
: never
: never;
```

`A``B``true`, `false` の他に `boolean``never`, `any` などが入ってくる可能性もあるため、 `TypeEq` で厳密一致するかどうかをチェックする実装にしています。 `true``false` になっていなければすべて `never` を返します。
Expand Down Expand Up @@ -155,11 +155,8 @@ Type Challenges^[[Type Challenges (IsUnion)](https://github.com/type-challenges/
type IsUnion<U> = _IsUnionImpl<U, U>;

/** @internal */
type _IsUnionImpl<U, K extends U> = IsNever<U> extends true
? false
: K extends K
? BoolNot<TypeEq<U, K>>
: never;
type _IsUnionImpl<U, K extends U> =
IsNever<U> extends true ? false : K extends K ? BoolNot<TypeEq<U, K>> : never;
```

まず与えられた型 `U``never` であれば `false` を返します。
Expand Down Expand Up @@ -246,16 +243,14 @@ expectType<IndexOfTuple<readonly []>, never>('=');
```ts
type IndexOfTuple<T extends readonly unknown[]> = _IndexOfTupleImpl<T, keyof T>;

type _IndexOfTupleImpl<
T extends readonly unknown[],
K,
> = IsFixedLengthList<T> extends true
? K extends keyof T
? K extends `${number}`
? ToNumber<K>
type _IndexOfTupleImpl<T extends readonly unknown[], K> =
IsFixedLengthList<T> extends true
? K extends keyof T
? K extends `${number}`
? ToNumber<K>
: never
: never
: never
: number;
: number;
```

タプル型 `T` から `keyof T` を取り出してそれらを `ToNumber` で map した結果を得るという実装です。 `K extends keyof T` のところで union distribution[^1] を使っています。
Expand Down Expand Up @@ -319,12 +314,16 @@ namespace _MakeTupleInternals {
> = string extends N
? never
: N extends ''
? X
: First<N> extends infer U
? U extends DigitStr
? MakeTupleImpl<T, Tail<N>, readonly [...Tile<[T], U>, ...Tile<X, 10>]>
: never
: never;
? X
: First<N> extends infer U
? U extends DigitStr
? MakeTupleImpl<
T,
Tail<N>,
readonly [...Tile<[T], U>, ...Tile<X, 10>]
>
: never
: never;
}
```

Expand Down
4 changes: 2 additions & 2 deletions config/eslintrc/generate-rules-type/generate-rules-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ const createRulePrefix = (
pluginName === 'eslint'
? ''
: rulePrefixOrNull !== undefined && rulePrefixOrNull !== ''
? rulePrefixOrNull
: `${pluginName.replace(/^eslint-plugin-/u, '')}/`;
? rulePrefixOrNull
: `${pluginName.replace(/^eslint-plugin-/u, '')}/`;

export const generateRulesType = (
typeName: string,
Expand Down
69 changes: 34 additions & 35 deletions docs/blog/immutable_utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,10 @@ export function setIn<R extends ReadonlyRecordBase>(
少々複雑な型を実装するので、型のユニットテストをするためのユーティリティを用意します。

```ts
export type TypeEq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
T,
>() => T extends Y ? 1 : 2
? true
: false;
export type TypeEq<X, Y> =
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
? true
: false;

export const assertType = <_T extends true>(): void => undefined;
export const assertNotType = <_T extends false>(): void => undefined;
Expand Down Expand Up @@ -320,8 +319,8 @@ assertNotType<TypeEq<{ x: any }, { x: number }>>();
export type DeepReadonly<T> = T extends (...args: readonly unknown[]) => unknown
? T
: T extends ReadonlyRecordBase | readonly unknown[]
? { readonly [P in keyof T]: DeepReadonly<T[P]> }
: T;
? { readonly [P in keyof T]: DeepReadonly<T[P]> }
: T;

assertType<
TypeEq<
Expand Down Expand Up @@ -504,12 +503,12 @@ type LeafPathsImplListCase<
> = T extends readonly []
? readonly []
: IsInfiniteList<T> extends true
? readonly []
: PathHead extends keyof T
? PathHead extends `${number}`
? readonly [ToNumber<PathHead>, ...LeafPaths<T[PathHead]>]
: never
: never;
? readonly []
: PathHead extends keyof T
? PathHead extends `${number}`
? readonly [ToNumber<PathHead>, ...LeafPaths<T[PathHead]>]
: never
: never;
```

`IsInfiniteList<T> extends true` のところは不定長の配列型の場合は再帰をストップするための処理です。 `IsInfiniteList` は、固定長のタプル型の `length` がその具体的な長さの数値リテラルになる(たとえば `[1, 3, 6]['length']` = `3` )ことを利用して `number` 以上に広い型になるかどうかで以下の判定できます。
Expand Down Expand Up @@ -747,28 +746,28 @@ const UNSAFE_setIn_impl = (
index >= keyPath.length
? newValue
: Array.isArray(record)
? record.map((v, i): unknown =>
i === keyPath[index]
? UNSAFE_setIn_impl(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
record[keyPath[index]!] as ReadonlyRecordBase,
keyPath,
index + 1,
newValue,
)
: v,
)
: {
...record,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
[keyPath[index]!]: UNSAFE_setIn_impl(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
record[keyPath[index]!] as ReadonlyRecordBase,
keyPath,
index + 1,
newValue,
),
};
? record.map((v, i): unknown =>
i === keyPath[index]
? UNSAFE_setIn_impl(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
record[keyPath[index]!] as ReadonlyRecordBase,
keyPath,
index + 1,
newValue,
)
: v,
)
: {
...record,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
[keyPath[index]!]: UNSAFE_setIn_impl(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
record[keyPath[index]!] as ReadonlyRecordBase,
keyPath,
index + 1,
newValue,
),
};

export const setIn = <R extends ReadonlyRecordBase>(
record: R,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ export const GameResultList = memo(

const [dialogIsOpen, setDialogIsOpen] = useState<boolean>(false)

const [selectedGameResult, setSelectedGameResult] = useState<TGameResult>(
GameResult(),
)
const [selectedGameResult, setSelectedGameResult] =
useState<TGameResult>(GameResult())

const closeDialog = useCallback(() => {
setDialogIsOpen(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export const GameResults = memo(() => {
v === 'reset'
? I.Set(numPlayersList)
: v.checked
? s.add(v.numPlayers)
: s.delete(v.numPlayers),
? s.add(v.numPlayers)
: s.delete(v.numPlayers),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export const DCardImage = memo(
: [widthInput * (15 / 23), widthInput]
: [heightInput, heightInput * (23 / 15)]
: heightInput === undefined
? widthInput === undefined
? [230, 150]
: [widthInput * (23 / 15), widthInput]
: [heightInput, heightInput * (15 / 23)],
? widthInput === undefined
? [230, 150]
: [widthInput * (23 / 15), widthInput]
: [heightInput, heightInput * (15 / 23)],
[isWide, heightInput, widthInput],
)

Expand Down
16 changes: 8 additions & 8 deletions experimental/immutable/src/js/CollectionImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ mixin(Collection, {
return isIndexed(this)
? this.toIndexedSeq()
: isKeyed(this)
? this.toKeyedSeq()
: this.toSetSeq();
? this.toKeyedSeq()
: this.toSetSeq();
},

toStack() {
Expand Down Expand Up @@ -764,12 +764,12 @@ function hashCollection(collection) {
h = (h + hashMerge(hash(v), hash(k))) | 0;
}
: ordered
? (v) => {
h = (31 * h + hash(v)) | 0;
}
: (v) => {
h = (h + hash(v)) | 0;
},
? (v) => {
h = (31 * h + hash(v)) | 0;
}
: (v) => {
h = (h + hash(v)) | 0;
},
);
return murmurHashOfSize(size, h);
}
Expand Down
16 changes: 8 additions & 8 deletions experimental/immutable/src/js/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export class List extends IndexedCollection {
return !this.has(index)
? this
: index === 0
? this.shift()
: index === this.size - 1
? this.pop()
: this.splice(index, 1);
? this.shift()
: index === this.size - 1
? this.pop()
: this.splice(index, 1);
}

insert(index, value) {
Expand Down Expand Up @@ -546,8 +546,8 @@ function setListBounds(list, begin, end) {
end === undefined
? oldCapacity
: end < 0
? oldCapacity + end
: oldOrigin + end;
? oldCapacity + end
: oldOrigin + end;
if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
return list;
}
Expand Down Expand Up @@ -595,8 +595,8 @@ function setListBounds(list, begin, end) {
newTailOffset < oldTailOffset
? listNodeFor(list, newCapacity - 1)
: newTailOffset > oldTailOffset
? new VNode([], owner)
: oldTail;
? new VNode([], owner)
: oldTail;

// Merge Tail into tree.
if (
Expand Down
12 changes: 6 additions & 6 deletions experimental/immutable/src/js/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export class Map extends KeyedCollection {
return value === null || value === undefined
? emptyMap()
: isMap(value) && !isOrdered(value)
? value
: emptyMap().withMutations((map) => {
const iter = KeyedCollection(value);
assertNotInfinite(iter.size);
iter.forEach((v, k) => map.set(k, v));
});
? value
: emptyMap().withMutations((map) => {
const iter = KeyedCollection(value);
assertNotInfinite(iter.size);
iter.forEach((v, k) => map.set(k, v));
});
}

static of(...keyValues) {
Expand Down
Loading

0 comments on commit 77cb852

Please sign in to comment.