Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typescript #216

Merged
merged 4 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"remark-preset-wooorm": "^9.0.0",
"tsd": "^0.24.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"typescript": "^5.0.0",
"xo": "^0.53.0"
},
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions test/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ test('process(file, done)', () => {
})
.use(
() =>
/**
* @param {Node} tree
* @param {VFile} file
*/
Comment on lines +50 to +53
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are needed by type coverage, tree was considered an implicit any

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was TypeScript able to infer its type before? This seems like a regression in TypeScript.

Copy link
Member Author

@ChristianMurphy ChristianMurphy Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, inside VSCode, both TS4.9 and TS5.0 show Node<Data> even without this annotation.
type-coverage is where the error appears
(correction, this is specific to TS5.0, see later comment)

unified/test/process.js:50:19: tree
unified/test/process.js:103:19: tree
unified/test/run.js:552:19: tree
unified/test/run.js:562:19: _
unified/test/use.js:255:19: node
2855 / 2860 99.82%

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like TS5 support in type-coverage is really new plantain-00/type-coverage#118
I'm double checking I have version v2.25.0 or higher locally now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is version v2.25.0 ✅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They’re asking the community to report regressions. I think this one would be a most welcome issue upstream. :)

I would like to update to TypeScript 5, but unless we want to use any new TypeScript features, I’m not in a hurry to update. I’d rather wait for an upstream fix than adding workarounds.

Copy link
Member Author

@ChristianMurphy ChristianMurphy Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is an interesting one, when I try to replicate the issue in the TS Playground, it works again.
(playground, playground 2 in either disable noUnusedLocals)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to update to TypeScript 5, but unless we want to use any new TypeScript features, I’m not in a hurry to update. I’d rather wait for an upstream fix than adding workarounds.

💯 agree

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update, as of TypeScript 5.1.6 and Type Coverage 2.26.0, it is still an any type.
typescript does not throw anymore, but type-coverage does.

unified/test/process.js:50:19: tree
2865 / 2866 99.96%
The type coverage rate(99.96%) is lower than the target(100%).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function (tree, file) {
assert.equal(tree, givenNode, 'should pass `tree` to transformers')
assert.equal(file, givenFile, 'should pass `file` to transformers')
Expand Down Expand Up @@ -100,6 +104,10 @@ test('process(file)', () => {
})
.use(
() =>
/**
* @param {Node} tree
* @param {VFile} file
*/
function (tree, file) {
assert.equal(tree, givenNode, 'should pass `tree` to transformers')
assert.equal(file, givenFile, 'should pass `file` to transformers')
Expand Down
12 changes: 12 additions & 0 deletions test/run.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @typedef {import('unist').Node} Node
*/

import process from 'node:process'
import assert from 'node:assert/strict'
import test from 'node:test'
Expand Down Expand Up @@ -549,6 +553,10 @@ test('runSync(node[, file])', async () => {
unified()
.use(
() =>
/**
* @param {Node} tree
* @param {VFile} file
*/
function (tree, file) {
assert.equal(tree, givenNode, 'passes given tree to transformers')
assert.equal(file, givenFile, 'passes given file to transformers')
Expand All @@ -559,6 +567,10 @@ test('runSync(node[, file])', async () => {
unified()
.use(
() =>
/**
* @param {Node} _
* @param {VFile} file
*/
function (_, file) {
assert.equal(
file.toString(),
Expand Down
28 changes: 20 additions & 8 deletions test/use.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @typedef {import('unist').Node} Node
* @typedef {import('vfile').VFile} VFile
*/

import assert from 'node:assert/strict'
import test from 'node:test'
import {unified} from '../index.js'
Expand Down Expand Up @@ -252,14 +257,21 @@ test('use(plugin[, options])', async (t) => {
const condition = true

processor
.use(() => (node, file) => {
assert.equal(node, givenNode, 'should attach a transformer (#1)')
assert.ok('message' in file, 'should attach a transformer (#2)')

if (condition) {
throw new Error('Alpha bravo charlie')
}
})
.use(
() =>
/**
* @param {Node} node
* @param {VFile} file
*/
function (node, file) {
assert.equal(node, givenNode, 'should attach a transformer (#1)')
assert.ok('message' in file, 'should attach a transformer (#2)')

if (condition) {
throw new Error('Alpha bravo charlie')
}
}
)
.freeze()

assert.throws(
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
"declaration": true,
"emitDeclarationOnly": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
"lib": ["es2020"],
"module": "node16",
"newLine": "lf",
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
"skipLibCheck": true,
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
"strict": true,
"target": "es2020"
}
Expand Down