Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove dependency on spec.ts to fix build issue #1104

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/draft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, _} from "spec.ts"
import {assert, _} from "./spec_ts"
import {produce, Draft, castDraft, original} from "../src/immer"

// For checking if a type is assignable to its draft type (and vice versa)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/immutable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, _} from "spec.ts"
import {assert, _} from "./spec_ts"
import {produce, Immutable, castImmutable} from "../src/immer"

test("types are ok", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/produce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, _} from "spec.ts"
import {assert, _} from "./spec_ts"
import {
produce,
applyPatches,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/redux.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, _} from "spec.ts"
import {assert, _} from "./spec_ts"
import {produce, Draft} from "../src/immer"
import * as redux from "redux"

Expand Down
56 changes: 56 additions & 0 deletions __tests__/spec_ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* This file is literally copied from https://github.com/aleclarson/spec.ts/blob/master/index.d.ts.
* For the sole reason, that the package somehow fails to install in our GitHub workflow.
* It is unclear why, but all credits to @aleclarson!
*/

// Give "any" its own class
export class Any {
// @ts-ignore
private _: true
}

// Conditional returns can enforce identical types.
// See here: https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650
// prettier-ignore
type TestExact<Left, Right> =
(<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? Any : never;

type IsAny<T> = Any extends T ? ([T] extends [Any] ? 1 : 0) : 0

export type Test<Left, Right> = IsAny<Left> extends 1
? IsAny<Right> extends 1
? 1
: "❌ Left type is 'any' but right type is not"
: IsAny<Right> extends 1
? "❌ Right type is 'any' but left type is not"
: [Left] extends [Right]
? [Right] extends [Left]
? Any extends TestExact<Left, Right>
? 1
: "❌ Unexpected or missing 'readonly' property"
: "❌ Right type is not assignable to left type"
: "❌ Left type is not assignable to right type"

type Assert<T, U> = U extends 1
? T // No error.
: IsAny<T> extends 1
? never // Ensure "any" is refused.
: U // Return the error message.

/**
* Raise a compiler error when both argument types are not identical.
*/
export const assert: <Left, Right>(
left: Assert<Left, Test<Left, Right>>,
right: Assert<Right, Test<Left, Right>>
) => Right = x => x as any

/**
* Placeholder value followed by "as T"
*/
export const _: any = Symbol("spec.ts placeholder")

test("empty test to silence jest", () => {
expect(true).toBeTruthy()
})
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"rimraf": "^2.6.2",
"seamless-immutable": "^7.1.3",
"semantic-release": "^17.0.2",
"spec.ts": "^1.1.0",
"ts-jest": "^29.0.0",
"tsup": "^6.7.0",
"typescript": "^5.0.2"
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8301,11 +8301,6 @@ spdx-license-ids@^3.0.0:
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.13.tgz#7189a474c46f8d47c7b0da4b987bb45e908bd2d5"
integrity sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==

spec.ts@^1.1.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/spec.ts/-/spec.ts-1.1.3.tgz#2951ed40a984386fdd5bb287719e67a1ceaafff1"
integrity sha512-xDzHAwbHqe9OIHT1c+pnVpVuYSHNC5vk51aFKKoql2aH1RCzHplkd7MoSV7uLfzgm3GmlfpAfwLtfH2T3lQMmw==

split-string@^3.0.1, split-string@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
Expand Down