geoffreytools / ts-spec Goto Github PK
View Code? Open in Web Editor NEWA small library for testing your types
License: ISC License
A small library for testing your types
License: ISC License
The fix in #5 caused a regression in TS 4.8.
In this version, Uppercase<string> | Lowercase<string> | Capitalize<string> | Uncapitalize<string>
can't be resolved to anything and any conditional type mentioning them makes the problem bubble up, to the point the entire disambiguation algorithm and the two operands of the comparison ultimately fail to resolve as well.
import {test} from 'ts-spec'
//Type 'FailingTest<"pass", number, number | undefined>' is not assignable to type 'PassingTest | PassingTest[]'.
test('pass' as const, (t) => t.equal(1 as number | undefined)<number | undefined>())
import { test } from 'ts-spec'
test('' as const, (t) => t.not.equal('' as Uppercase<string>)<Lowercase<string>>()) // error
I would like a way to write a test like the following:
interface Foo {
foo: string | number;
}
test("{ foo: 10 } is assignable to Foo", (t) => t.assignable({ foo: 10 })<Foo>());
This seems to be subtly different to extends
and includes
in that extends
tests that A is a strict superset of B instead of testing that A is sufficient to satisfy B.
import { test } from 'ts-spec'
test('' as const, (t) => t.not.equal({} as { a: number; b?: string })<{ a: number }>())) // error
The follow usage used to work in 1.4.0 and doesn't work in the current release:
class Foo {}
const foo = { foo: Foo } as const;
test("object maps to constructors", (t) => t.equal(foo)<{ readonly foo: new () => Foo }>());
I'm not sure if this is a bug or if I'm misusing the testing library but I can't make this case work out again now.
// It looks like this succeeds:
test("class includes a constructor", (t) => t.includes<Foo, new () => Foo>());
// But both of these fail:
test("class includes a constructor", (t) => t.includes(Foo)<new () => Foo>();
test("object maps to constructors", (t) => t.includes(foo)<{ foo: new () => Foo }>());
@geoffreytools i can't seem to get anything to fail in ts-spec
import { test } from 'ts-spec';
test('test description' as const, t =>
t.equal(1)<string>() // no error
);
Originally posted by @DetachHead in microsoft/TypeScript#27024 (comment)
import { test } from 'ts-spec'
interface Foo {
readonly a: number
}
declare const foo: { a: number }
test('' as const, (t) => t.not.equal(foo)<Foo>()) // error
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.