From 30b53e2f8359a42c970f59fa1fac7e318c43568a Mon Sep 17 00:00:00 2001 From: baseballyama Date: Sun, 23 Apr 2023 15:08:27 +0900 Subject: [PATCH] revert type tests --- test/types/actions.js | 221 ------------------ test/types/actions.ts | 129 ++++++++++ ...spatcher.js => create-event-dispatcher.ts} | 0 test/types/tsconfig.json | 6 +- 4 files changed, 131 insertions(+), 225 deletions(-) delete mode 100644 test/types/actions.js create mode 100644 test/types/actions.ts rename test/types/{create-event-dispatcher.js => create-event-dispatcher.ts} (100%) diff --git a/test/types/actions.js b/test/types/actions.js deleted file mode 100644 index f31fa55cb9..0000000000 --- a/test/types/actions.js +++ /dev/null @@ -1,221 +0,0 @@ -const nullAsAny = /** @type {any} */(null); - -// ---------------- Action - -/** - * @type {import ('$runtime/action').Action} - */ -const href = (node) => { - node.href = ''; - // @ts-expect-error - node.href = 1; -}; -href; - -/** - * @type {import ('$runtime/action').Action} - */ -const required = (node, param) => { - node; - param; -}; -required(nullAsAny, true); -// @ts-expect-error (only in strict mode) boolean missing -required(nullAsAny); -// @ts-expect-error no boolean -required(nullAsAny, 'string'); - -/** - * @type {import ('$runtime/action').Action} - */ -const required1 = (node, param) => { - node; - param; - return { - update: (p) => p === true, - destroy: () => { } - }; -}; -required1; - -/** - * @type {import ('$runtime/action').Action} - */ -const required2 = (node) => { - node; -}; -required2; - -/** - * @type {import ('$runtime/action').Action} - */ -const required3 = (node, param) => { - node; - param; - return { - // @ts-expect-error comparison always resolves to false - update: (p) => p === 'd', - destroy: () => { } - }; -}; -required3; - -/** - * @type {import ('$runtime/action').Action} - */ -const optional = (node, param) => { - node; - param; -}; -optional(nullAsAny, true); -optional(nullAsAny); -// @ts-expect-error no boolean -optional(nullAsAny, 'string'); - -/** - * @type {import ('$runtime/action').Action} - */ -const optional1 = (node, param) => { - node; - param; - return { - update: (p) => p === true, - destroy: () => { } - }; -}; -optional1; - -/** - * @type {import ('$runtime/action').Action} - */ -const optional2 = (node) => { - node; -}; -optional2; - -/** - * @type {import ('$runtime/action').Action} - */ -const optional3 = (node, param) => { - node; - param; -}; -optional3; - -/** - * @type {import ('$runtime/action').Action} - */ -const optional4 = (node, param) => { - node; - param; - return { - // @ts-expect-error comparison always resolves to false - update: (p) => p === 'd', - destroy: () => { } - }; -}; -optional4; - -/** - * @type {import ('$runtime/action').Action} - */ -const no = (node) => { - node; -}; -// @ts-expect-error second param -no(nullAsAny, true); -no(nullAsAny); -// @ts-expect-error second param -no(nullAsAny, 'string'); - -/** - * @type {import ('$runtime/action').Action} - */ -const no1 = (node) => { - node; - return { - destroy: () => { } - }; -}; -no1; - -/** - * @type {import ('$runtime/action').Action} - */ -// @ts-expect-error param given -const no2 = (node, param) => { }; -no2; - -/** - * @type {import ('$runtime/action').Action} - */ -// @ts-expect-error param given -const no3 = (node, param) => { }; -no3; - -/** - * @type {import ('$runtime/action').Action} - */ -const no4 = (_node) => { - return { - // @ts-expect-error update method given - update: () => { }, - destroy: () => { } - }; -}; -no4; - -// ---------------- ActionReturn - -/** - * @type {import ('$runtime/action').ActionReturn} - */ -const requiredReturn = { - update: (p) => p.toString() -}; -requiredReturn; - -/** - * @type {import ('$runtime/action').ActionReturn} - */ -const optionalReturn = { - update: (p) => { - p === true; - // @ts-expect-error could be undefined - p.toString(); - } -}; -optionalReturn; - -/** - * @type {import ('$runtime/action').ActionReturn} - */ -const invalidProperty = { - // @ts-expect-error invalid property - invalid: () => { } -}; -invalidProperty; - -/** - * @typedef {import ('$runtime/action').ActionReturn['$$_attributes']} Attributes - */ - -/** - * @type {Attributes} - */ -const attributes = { a: 'a' }; -attributes; - -/** - * @type {Attributes} - */ -// @ts-expect-error wrong type -const invalidAttributes1 = { a: 1 }; -invalidAttributes1; - -/** - * @type {Attributes} - */ -// @ts-expect-error missing prop -const invalidAttributes2 = {}; -invalidAttributes2; diff --git a/test/types/actions.ts b/test/types/actions.ts new file mode 100644 index 0000000000..3d56aa3605 --- /dev/null +++ b/test/types/actions.ts @@ -0,0 +1,129 @@ +import type { Action, ActionReturn } from '$runtime/action'; + +// ---------------- Action + +const href: Action = (node) => { + node.href = ''; + // @ts-expect-error + node.href = 1; +}; +href; + +const required: Action = (_node, _param) => {}; +required(null as any, true); +// @ts-expect-error (only in strict mode) boolean missing +required(null as any); +// @ts-expect-error no boolean +required(null as any, 'string'); + +const required1: Action = (_node, _param) => { + return { + update: (p) => p === true, + destroy: () => {} + }; +}; +required1; + +const required2: Action = (_node) => {}; +required2; + +const required3: Action = (_node, _param) => { + return { + // @ts-expect-error comparison always resolves to false + update: (p) => p === 'd', + destroy: () => {} + }; +}; +required3; + +const optional: Action = (_node, _param?) => {}; +optional(null as any, true); +optional(null as any); +// @ts-expect-error no boolean +optional(null as any, 'string'); + +const optional1: Action = (_node, _param?) => { + return { + update: (p) => p === true, + destroy: () => {} + }; +}; +optional1; + +const optional2: Action = (_node) => {}; +optional2; + +const optional3: Action = (_node, _param) => {}; +optional3; + +const optional4: Action = (_node, _param?) => { + return { + // @ts-expect-error comparison always resolves to false + update: (p) => p === 'd', + destroy: () => {} + }; +}; +optional4; + +const no: Action = (_node) => {}; +// @ts-expect-error second param +no(null as any, true); +no(null as any); +// @ts-expect-error second param +no(null as any, 'string'); + +const no1: Action = (_node) => { + return { + destroy: () => {} + }; +}; +no1; + +// @ts-expect-error param given +const no2: Action = (_node, _param?) => {}; +no2; + +// @ts-expect-error param given +const no3: Action = (_node, _param) => {}; +no3; + +// @ts-expect-error update method given +const no4: Action = (_node) => { + return { + update: () => {}, + destroy: () => {} + }; +}; +no4; + +// ---------------- ActionReturn + +const requiredReturn: ActionReturn = { + update: (p) => p.toString() +}; +requiredReturn; + +const optionalReturn: ActionReturn = { + update: (p) => { + p === true; + // @ts-expect-error could be undefined + p.toString(); + } +}; +optionalReturn; + +const invalidProperty: ActionReturn = { + // @ts-expect-error invalid property + invalid: () => {} +}; +invalidProperty; + +type Attributes = ActionReturn['$$_attributes']; +const attributes: Attributes = { a: 'a' }; +attributes; +// @ts-expect-error wrong type +const invalidAttributes1: Attributes = { a: 1 }; +invalidAttributes1; +// @ts-expect-error missing prop +const invalidAttributes2: Attributes = {}; +invalidAttributes2; diff --git a/test/types/create-event-dispatcher.js b/test/types/create-event-dispatcher.ts similarity index 100% rename from test/types/create-event-dispatcher.js rename to test/types/create-event-dispatcher.ts diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json index f4e007ba51..108ed2a2b2 100644 --- a/test/types/tsconfig.json +++ b/test/types/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "../..", + "rootDir": "../..", "baseUrl": "../../", "paths": { "$runtime/*": ["src/runtime/*"] @@ -11,8 +11,6 @@ "noFallthroughCasesInSwitch": true, "noImplicitReturns": true, "strict": true, - "allowJs": true, - "checkJs": true }, "include": ["."] -} +} \ No newline at end of file