add types tests

pull/7324/head
Ivan Hofer 5 years ago
parent 5491871968
commit d224566435

@ -83,8 +83,9 @@
}, },
"types": "types/runtime/index.d.ts", "types": "types/runtime/index.d.ts",
"scripts": { "scripts": {
"test": "mocha --exit", "test": "mocha --exit && npm run test:types",
"test:unit": "mocha --require sucrase/register --recursive src/**/__test__.ts --exit", "test:unit": "mocha --require sucrase/register --recursive src/**/__test__.ts --exit",
"test:types": "tsc --project test/types/tsconfig.json --noEmit",
"quicktest": "mocha", "quicktest": "mocha",
"build": "rollup -c && npm run tsd", "build": "rollup -c && npm run tsd",
"prepare": "npm run build", "prepare": "npm run build",

@ -0,0 +1,33 @@
import { createEventDispatcher } from '$runtime/internal/lifecycle';
const dispatch = createEventDispatcher<{
loaded: never
change: string
valid: boolean
optional: number | null
}>();
// @ts-expect-error: dispatch invalid event
dispatch('some-event');
dispatch('loaded');
// @ts-expect-error: no detail accepted
dispatch('loaded', 123);
// @ts-expect-error: detail not provided
dispatch('change');
dispatch('change', 'string');
// @ts-expect-error: wrong type of detail
dispatch('change', 123);
// @ts-expect-error: wrong type of detail
dispatch('change', undefined);
dispatch('valid', true);
// @ts-expect-error: wrong type of detail
dispatch('valid', 'string');
dispatch('optional');
dispatch('optional', 123);
dispatch('optional', null);
// @ts-expect-error: wrong type of optional detail
dispatch('optional', 'string');

@ -0,0 +1,28 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"isolatedModules": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "../../",
"allowJs": true,
"checkJs": true,
"paths": {
"$runtime/*": ["src/runtime/*"]
},
// enable strictest options
"allowUnreachableCode": false,
"alwaysStrict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"strict": true,
},
"include": ["**/*.test-types.ts"]
}
Loading…
Cancel
Save