Skip to content

Proposal setup to make the TypeScript migration easier #614

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['kcd-scripts/babel', '@babel/preset-typescript'],
}
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"test:debug": "node --inspect-brk ./node_modules/.bin/jest --watch --runInBand",
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate",
"generate-types": "tsc",
"typecheck": "dtslint ./types/"
},
"files": [
Expand All @@ -41,16 +42,18 @@
"@babel/runtime": "^7.10.2",
"aria-query": "^4.0.2",
"dom-accessibility-api": "^0.4.5",
"eslint-import-resolver-typescript": "^2.0.0",
"pretty-format": "^25.5.0"
},
"devDependencies": {
"dtslint": "^3.6.9",
"@testing-library/jest-dom": "^5.9.0",
"dtslint": "^3.6.9",
"jest-in-case": "^1.0.2",
"jest-serializer-ansi": "^1.0.3",
"jest-watch-select-projects": "^2.0.0",
"jsdom": "^16.2.2",
"kcd-scripts": "^6.2.0"
"kcd-scripts": "^6.2.0",
"typescript": "^3.9.5"
},
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js",
Expand All @@ -59,6 +62,11 @@
"import/no-unassigned-import": "off",
"import/no-useless-path-segments": "off",
"no-console": "off"
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
},
"eslintIgnore": [
Expand Down
4 changes: 2 additions & 2 deletions src/get-node-text.js → src/get-node-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType#Node_type_constants
const TEXT_NODE = 3

function getNodeText(node) {
function getNodeText(node: HTMLElement): string {
if (node.matches('input[type=submit], input[type=button]')) {
return node.value
return (node as HTMLInputElement).value
}

return Array.from(node.childNodes)
Expand Down
6 changes: 6 additions & 0 deletions tests/jest.config.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ module.exports = {
'/__node_tests__/',
],
testEnvironment: 'jest-environment-jsdom',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': path.join(
__dirname,
'../node_modules/kcd-scripts/dist/config/babel-transform',
),
},
}
6 changes: 6 additions & 0 deletions tests/jest.config.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ module.exports = {
'/__node_tests__/',
],
testMatch: ['**/__node_tests__/**.js'],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': path.join(
__dirname,
'../node_modules/kcd-scripts/dist/config/babel-transform',
),
},
}
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"outDir": "./types/",
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["./src/**/*.ts"]
}
3 changes: 2 additions & 1 deletion types/get-node-text.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export function getNodeText(node: HTMLElement): string;
declare function getNodeText(node: HTMLElement): string;
export { getNodeText };
Copy link
Member

Choose a reason for hiding this comment

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

Same here. Do we need .d.ts files when the source is in TypeScript?

Choose a reason for hiding this comment

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

shouldn't need to. Might need to add the -d flag when compiling or set that in your tsconfig.