From 4805654929f9aeeef939ea89434dcceef8b2f93b Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 15:35:29 -0400 Subject: [PATCH 01/10] Copy over Types and type-tests from DT: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ember__string --- index.d.ts | 7 ++++++ package.json | 4 +++- type-tests/the-tests.ts | 51 ++++++++++++++++++++++++++++++++++++++++ type-tests/tsconfig.json | 8 +++++++ yarn.lock | 13 ++++++---- 5 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 index.d.ts create mode 100644 type-tests/the-tests.ts create mode 100644 type-tests/tsconfig.json diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..6a6f95b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,7 @@ +export function camelize(str: string): string; +export function capitalize(str: string): string; +export function classify(str: string): string; +export function dasherize(str: string): string; +export function decamelize(str: string): string; +export function underscore(str: string): string; +export function w(str: string): string[]; diff --git a/package.json b/package.json index 823c033..ef73730 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "start": "ember serve", "test": "npm-run-all lint test:*", "test:ember": "ember test", + "test:types": "tsc --noEmit --project ./type-tests/tsconfig.json", "test:ember-compatibility": "ember try:each", "test-typings": "node node_modules/typescript/bin/tsc", "prepack": "yarn babel --extensions '.ts' --presets @babel/preset-typescript addon --out-dir addon/ --ignore '**/*.d.ts'", @@ -42,6 +43,7 @@ "@embroider/test-setup": "^0.47.1", "@glimmer/component": "^1.0.4", "@glimmer/tracking": "^1.0.4", + "@tsconfig/ember": "^2.0.0", "@types/ember": "^3.16.5", "@types/ember-qunit": "^3.4.14", "@types/ember__test-helpers": "^2.0.2", @@ -84,7 +86,7 @@ "release-it": "^14.11.6", "release-it-lerna-changelog": "^3.1.0", "rimraf": "^3.0.2", - "typescript": "^4.4.4", + "typescript": "^5.0.4", "webpack": "^5" }, "engines": { diff --git a/type-tests/the-tests.ts b/type-tests/the-tests.ts new file mode 100644 index 0000000..7c520af --- /dev/null +++ b/type-tests/the-tests.ts @@ -0,0 +1,51 @@ +import { + dasherize, + camelize, + capitalize, + classify, + decamelize, + underscore, + w, +} from '@ember/string'; + +// @ts-expect-error +dasherize(); +dasherize('blue man group'); // $ExpectType string +// @ts-expect-error +dasherize('', ''); + +// @ts-expect-error +camelize(); +camelize('blue man group'); // $ExpectType string +// @ts-expect-error +camelize('', ''); + +// @ts-expect-error +decamelize(); +decamelize('blue man group'); // $ExpectType string +// @ts-expect-error +decamelize('', ''); + +// @ts-expect-error +underscore(); +underscore('blue man group'); // $ExpectType string +// @ts-expect-error +underscore('', ''); + +// @ts-expect-error +w(); +w('blue man group'); // $ExpectType string[] +// @ts-expect-error +w('', ''); + +// @ts-expect-error +classify(); +classify('blue man group'); // $ExpectType string +// @ts-expect-error +classify('', ''); + +// @ts-expect-error +capitalize(); +capitalize('blue man group'); // $ExpectType string +// @ts-expect-error +capitalize('', ''); diff --git a/type-tests/tsconfig.json b/type-tests/tsconfig.json new file mode 100644 index 0000000..0091664 --- /dev/null +++ b/type-tests/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "@tsconfig/ember", + "compilerOptions": { + "paths": { + "@ember/string": ["../"] + } + } +} diff --git a/yarn.lock b/yarn.lock index b5a1dc5..fc4b79b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1774,6 +1774,11 @@ resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== +"@tsconfig/ember@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@tsconfig/ember/-/ember-2.0.0.tgz#dba953e5527ccf7a2587f262a7afe0fa83c4e979" + integrity sha512-RzbDYYcjxVdG8Ki0xe99HN3+nHTZe6EBgw6N7B3yup7QogVFQQxA9nY7X80j1XzF15xqetwWiYfAjv5lkkp0/A== + "@types/body-parser@*": version "1.19.1" resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.1.tgz#0c0174c42a7d017b818303d4b5d969cb0b75929c" @@ -12499,10 +12504,10 @@ typescript-memoize@^1.0.0-alpha.3: resolved "https://registry.yarnpkg.com/typescript-memoize/-/typescript-memoize-1.0.1.tgz#0a8199aa28f6fe18517f6e9308ef7bfbe9a98d59" integrity sha512-oJNge1qUrOK37d5Y6Ly2txKeuelYVsFtNF6U9kXIN7juudcQaHJQg2MxLOy0CqtkW65rVDYuTCOjnSIVPd8z3w== -typescript@^4.4.4: - version "4.4.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" - integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== +typescript@^5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" + integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6" From 17eeb955eaa77317d56f922428332a6f14f5a061 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 15:37:59 -0400 Subject: [PATCH 02/10] Add CI --- .github/workflows/ci-build.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 4c0424e..fe5baa1 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -36,6 +36,31 @@ jobs: - run: yarn install --no-lockfile - run: yarn test:ember + types-scenarios: + name: "Types: ${{ matrix.tsVersion }}" + runs-on: ubuntu-latest + needs: test + + strategy: + matrix: + tsVersion: + - 4.4 + - 4.6 + - 4.8 + - 5.0 + - 5.1 + steps: + - uses: actions/checkout@v2 + - uses: volta-cli/action@v1 + - name: install dependencies + run: yarn install --frozen-lockfile + - name: Swap TS Version + run: yarn add --dev typescript@{{ matrix.tsVersion }} + - name: Check Types + run: | + tsc -v + yarn test:types + try-scenarios: name: "Try: ${{ matrix.ember-try-scenario }}" @@ -89,4 +114,4 @@ jobs: - name: publish to npm run: npm publish env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} \ No newline at end of file + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} From 09548f263effabb7881702b68770879efe634146 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 15:48:43 -0400 Subject: [PATCH 03/10] Use expect-type --- package.json | 1 + type-tests/the-tests.ts | 23 ++++++++++++++++------- yarn.lock | 5 +++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index ef73730..a4989e3 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-qunit": "^7.3.4", + "expect-type": "^0.15.0", "loader.js": "^4.7.0", "npm-run-all": "^4.1.5", "prettier": "^2.6.0", diff --git a/type-tests/the-tests.ts b/type-tests/the-tests.ts index 7c520af..bee8d69 100644 --- a/type-tests/the-tests.ts +++ b/type-tests/the-tests.ts @@ -8,44 +8,53 @@ import { w, } from '@ember/string'; +import { expectTypeOf } from 'expect-type'; + // @ts-expect-error dasherize(); -dasherize('blue man group'); // $ExpectType string // @ts-expect-error dasherize('', ''); +expectTypeOf(dasherize('blue man group')).toBeString() + // @ts-expect-error camelize(); -camelize('blue man group'); // $ExpectType string // @ts-expect-error camelize('', ''); +expectTypeOf(camelize('blue man group')).toBeString(); + // @ts-expect-error decamelize(); -decamelize('blue man group'); // $ExpectType string // @ts-expect-error decamelize('', ''); +expectTypeOf(decamelize('blue man group')).toBeString(); + // @ts-expect-error underscore(); -underscore('blue man group'); // $ExpectType string // @ts-expect-error underscore('', ''); +expectTypeOf(underscore('blue man group')).toBeString(); + // @ts-expect-error w(); -w('blue man group'); // $ExpectType string[] // @ts-expect-error w('', ''); +expectTypeOf(w('blue man group')).toMatchTypeOf(); + // @ts-expect-error classify(); -classify('blue man group'); // $ExpectType string // @ts-expect-error classify('', ''); +expectTypeOf(classify('blue man group')).toBeString(); + // @ts-expect-error capitalize(); -capitalize('blue man group'); // $ExpectType string // @ts-expect-error capitalize('', ''); + +expectTypeOf(capitalize('blue man group')).toBeString(); diff --git a/yarn.lock b/yarn.lock index fc4b79b..1fbff0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6365,6 +6365,11 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2: dependencies: homedir-polyfill "^1.0.1" +expect-type@^0.15.0: + version "0.15.0" + resolved "https://registry.yarnpkg.com/expect-type/-/expect-type-0.15.0.tgz#89f75e22c88554844ea2b2faf4ef5fc2e579d3b5" + integrity sha512-yWnriYB4e8G54M5/fAFj7rCIBiKs1HAACaY13kCz6Ku0dezjS9aMcfcdVK2X8Tv2tEV1BPz/wKfQ7WA4S/d8aA== + express@^4.10.7, express@^4.17.1: version "4.18.2" resolved "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz#3fabe08296e930c796c19e3c516979386ba9fd59" From 12efafbe707114e3145683fcdda7839cbf154142 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 15:49:33 -0400 Subject: [PATCH 04/10] Change tsVersion matrix to be 4.9+ --- .github/workflows/ci-build.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index fe5baa1..405849c 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -44,9 +44,7 @@ jobs: strategy: matrix: tsVersion: - - 4.4 - - 4.6 - - 4.8 + - 4.9 - 5.0 - 5.1 steps: From 6d1b289b502da597d157c5eeb29e113d77ebd1c6 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 15:50:27 -0400 Subject: [PATCH 05/10] Fix typo in types-scenarios task --- .github/workflows/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 405849c..5b0c12d 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -53,7 +53,7 @@ jobs: - name: install dependencies run: yarn install --frozen-lockfile - name: Swap TS Version - run: yarn add --dev typescript@{{ matrix.tsVersion }} + run: yarn add --dev typescript@${{ matrix.tsVersion }} - name: Check Types run: | tsc -v From 63c3fb5faf39cb66f61089b0b81dff286e6d95e3 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 15:52:07 -0400 Subject: [PATCH 06/10] lint:fix --- type-tests/the-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/type-tests/the-tests.ts b/type-tests/the-tests.ts index bee8d69..e00fa64 100644 --- a/type-tests/the-tests.ts +++ b/type-tests/the-tests.ts @@ -15,7 +15,7 @@ dasherize(); // @ts-expect-error dasherize('', ''); -expectTypeOf(dasherize('blue man group')).toBeString() +expectTypeOf(dasherize('blue man group')).toBeString(); // @ts-expect-error camelize(); From 08eab70860b702126d2b5847f05c8bd8d88a6e74 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 15:56:12 -0400 Subject: [PATCH 07/10] Stumble through using yarn to swap out the TS Version --- .github/workflows/ci-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 5b0c12d..93c58a1 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -44,9 +44,9 @@ jobs: strategy: matrix: tsVersion: - - 4.9 - - 5.0 - - 5.1 + - '~4.9' + - '~5.0' + - '~5.1' steps: - uses: actions/checkout@v2 - uses: volta-cli/action@v1 From 49f5a3eedabe90cebc39be276f8b4fc0af7d6f9b Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 16:00:26 -0400 Subject: [PATCH 08/10] 5.1 is still pre-release, so switch the types matrix to use the 'beta' tag --- .github/workflows/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 93c58a1..1b1cde1 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -46,7 +46,7 @@ jobs: tsVersion: - '~4.9' - '~5.0' - - '~5.1' + - 'beta' steps: - uses: actions/checkout@v2 - uses: volta-cli/action@v1 From d1f54f303bcd14bac3f0314cf32469c06975c964 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 16:03:08 -0400 Subject: [PATCH 09/10] Maybe yarn needs to invoke tsc --- .github/workflows/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 1b1cde1..34b3bd2 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -56,7 +56,7 @@ jobs: run: yarn add --dev typescript@${{ matrix.tsVersion }} - name: Check Types run: | - tsc -v + yarn tsc -v yarn test:types try-scenarios: From 01257759e39c8da65138106cabb6f22bfed1c92b Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 15 May 2023 16:04:12 -0400 Subject: [PATCH 10/10] Run the types-scenarios checking with node 14, instead of the volta-default of 12 -- TS 5.1 does not support node 12 --- .github/workflows/ci-build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 34b3bd2..cf5b5a7 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -50,6 +50,9 @@ jobs: steps: - uses: actions/checkout@v2 - uses: volta-cli/action@v1 + with: + # TS 5.1 does not support node 12 + node-version: 14.x - name: install dependencies run: yarn install --frozen-lockfile - name: Swap TS Version