Skip to content

Commit

Permalink
chore: remove tsd
Browse files Browse the repository at this point in the history
TSD has weird regressions with vue-next 3.0.9, maybe due to TS 4.2.
Instead of figthing it, let's adopt what the other Vue project did and replace TSD with a plain `tsc` check.

See vuejs/core@97dedeb for example for a similar commit on vue-next
  • Loading branch information
cexbrayat committed Mar 31, 2021
1 parent a3cb7f3 commit ee42325
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 546 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"rollup": "^2.44.0",
"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "25.3.1",
"tsd": "0.14.0",
"typescript": "^4.2.3",
"vitepress": "^0.12.2",
"vue": "3.0.7",
Expand All @@ -54,7 +53,7 @@
"scripts": {
"test": "yarn jest --runInBand tests",
"test:build": "yarn jest --runInBand tests -use-build",
"tsd": "tsd",
"tsd": "tsc -p test-dts/tsconfig.tsd.json",
"build": "yarn rollup -c rollup.config.js",
"lint": "prettier -c --parser typescript \"(src|tests)/**/*.ts?(x)\"",
"lint:fix": "yarn lint --write",
Expand Down
2 changes: 1 addition & 1 deletion test-dts/getComponent.d-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectType } from 'tsd'
import { expectType } from './index'
import { defineComponent, ComponentPublicInstance } from 'vue'
import { mount } from '../src'

Expand Down
17 changes: 17 additions & 0 deletions test-dts/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This directory contains a number of d.ts assertions using tsd:
// https://github.com/SamVerschueren/tsd
// The tests checks type errors and will probably show up red in VSCode, and
// it's intended. We cannot use directives like @ts-ignore or @ts-nocheck since
// that would suppress the errors that should be caught.

export function describe(_name: string, _fn: () => void): void

export function expectType<T>(value: T): void
export function expectError<T>(value: T): void
export function expectAssignable<T, T2 extends T = T>(value: T2): void

export type IsUnion<T, U extends T = T> = (T extends any
? (U extends T ? false : true)
: never) extends false
? false
: true
13 changes: 7 additions & 6 deletions test-dts/mount.d-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { expectError, expectType } from 'tsd'
import { expectError, expectType } from './index'
import {
DefineComponent,
defineComponent,
FunctionalComponent,
reactive
FunctionalComponent
} from 'vue'
import { Options, Vue } from 'vue-class-component'
import { mount } from '../src'
Expand Down Expand Up @@ -49,8 +48,8 @@ mount(AppWithDefine, {
props: { a: 'Hello', c: 2 }
})

// wrong prop type should not compile
expectError(
// @ts-expect-error wrong prop type should not compile
mount(AppWithDefine, {
props: { a: 2 }
})
Expand All @@ -77,9 +76,9 @@ mount(AppWithProps, {
props: { a: 'Hello', b: 2 }
})

// wrong prop type should not compile
expectError(
mount(AppWithProps, {
// @ts-expect-error wrong prop type should not compile
props: { a: 2 }
})
)
Expand Down Expand Up @@ -127,7 +126,7 @@ mount(AppWithoutProps, {

// Functional tests

// wrong props
// @ts-expect-error wrong props
expectError((props: { a: 1 }) => {}, {
props: {
a: '222'
Expand Down Expand Up @@ -208,6 +207,7 @@ class ClassComponent extends Vue {
}
}

// @ts-expect-error changeMessage expects an argument
expectError(mount(ClassComponent, {}).vm.changeMessage())
mount(ClassComponent, {}).vm.changeMessage('')

Expand All @@ -234,6 +234,7 @@ mount(Foo, {

expectError(
mount(
// @ts-expect-error
defineComponent({
props: {
baz: String,
Expand Down
6 changes: 5 additions & 1 deletion test-dts/plugins.d-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectError, expectType } from 'tsd'
import { expectError } from './index'
import { ComponentPublicInstance } from 'vue'
import { config, VueWrapper } from '../src'

Expand Down Expand Up @@ -40,7 +40,11 @@ config.plugins.VueWrapper.install(PluginWithOptionalOptions2, { msg: 'hello' })

// uncertain if it is possible to forbid this usage
// expectError(config.plugins.VueWrapper.install(PluginWithoutOptions, {}))
// @ts-expect-error option has the wrong type
expectError(config.plugins.VueWrapper.install(PluginWithOptions, { msg: true }))
// @ts-expect-error option is mandatory
expectError(config.plugins.VueWrapper.install(PluginWithOptions, {}))
// @ts-expect-error option is mandatory
expectError(config.plugins.VueWrapper.install(PluginWithOptionalOptions, {}))
// @ts-expect-error option is mandatory
expectError(config.plugins.VueWrapper.install(PluginWithOptionalOptions2, {}))
7 changes: 4 additions & 3 deletions test-dts/shallowMount.d-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectError, expectType } from 'tsd'
import { expectError, expectType } from './index'
import { defineComponent } from 'vue'
import { Options, Vue } from 'vue-class-component'
import { shallowMount } from '../src'
Expand Down Expand Up @@ -26,8 +26,8 @@ shallowMount(AppWithDefine, {
props: { a: 'Hello', c: 2 }
})

// wrong prop type should not compile
expectError(
// @ts-expect-error wrong prop type should not compile
shallowMount(AppWithDefine, {
props: { a: 2 }
})
Expand Down Expand Up @@ -56,9 +56,9 @@ shallowMount(AppWithProps, {
props: { a: 'Hello', b: 2 }
})

// wrong prop type should not compile
expectError(
shallowMount(AppWithProps, {
// @ts-expect-error wrong prop type should not compile
props: { a: 2 }
})
)
Expand Down Expand Up @@ -107,5 +107,6 @@ class ClassComponent extends Vue {
}
}

// @ts-expect-error changeMessage expects an argument
expectError(shallowMount(ClassComponent, {}).vm.changeMessage())
shallowMount(ClassComponent, {}).vm.changeMessage('')
16 changes: 16 additions & 0 deletions test-dts/tsconfig.tsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"skipLibCheck": true,
"experimentalDecorators": true,
"strictNullChecks": false
},
"exclude": [
"../src",
],
"include": [
"../dist",
"../test-dts"
]
}
2 changes: 1 addition & 1 deletion test-dts/wrapper.d-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectType } from 'tsd'
import { expectType } from './index'
import { defineComponent } from 'vue'
import { mount } from '../src'

Expand Down
Loading

0 comments on commit ee42325

Please sign in to comment.