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

WIP: Typescript Support! #5647

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions addon/transforms/string.js → addon/transforms/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import Transform from './transform';
@namespace DS
*/
export default Transform.extend({
deserialize(serialized) {
deserialize(serialized: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are null, undefined and non-serializable objects (i.e., circular references) valid things to pass here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unsure, I started this file as the first TS file just to see if I could get a build/tests going.

One of the things I'm excited about with the TS conversion, is that anybody will be able to answer that question :)

return none(serialized) ? null : String(serialized);
},
serialize(deserialized) {
serialize(deserialized: any) {
return none(deserialized) ? null : String(deserialized);
},
});
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"test-external:factory-guy": "node ./lib/scripts/test-external factory-guy https://github.com/danielspaniel/ember-data-factory-guy.git",
"test-external:ilios-frontend": "node ./lib/scripts/test-external ilios-frontend https://github.com/ilios/frontend.git --skip-smoke-test",
"test-external:ember-resource-metadata": "node ./lib/scripts/test-external ember-resource-metadata https://github.com/ef4/ember-resource-metadata.git",
"test-external:ember-data-relationship-tracker": "node ./lib/scripts/test-external ember-data-relationship-tracker https://github.com/ef4/ember-data-relationship-tracker.git"
"test-external:ember-data-relationship-tracker": "node ./lib/scripts/test-external ember-data-relationship-tracker https://github.com/ef4/ember-data-relationship-tracker.git",
"prepublishOnly": "ember ts:precompile",
"postpublish": "ember ts:clean"
},
"author": "",
"license": "MIT",
Expand Down Expand Up @@ -61,6 +63,13 @@
"devDependencies": {
"@ember-decorators/babel-transforms": "^2.1.2",
"@ember-decorators/data": "^3.0.0",
"@types/ember": "~3.0.25",
"@types/ember-qunit": "~3.4.3",
"@types/ember-test-helpers": "~1.0.4",
"@types/ember-testing-helpers": "~0.0.3",
"@types/ember__test-helpers": "~0.7.6",
"@types/qunit": "~2.5.3",
"@types/rsvp": "~4.0.2",
"babel-eslint": "^10.0.1",
"broccoli-babel-transpiler": "^7.0.0",
"broccoli-concat": "^3.7.3",
Expand All @@ -83,6 +92,8 @@
"ember-cli-shims": "^1.2.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-test-loader": "^2.2.0",
"ember-cli-typescript": "2.0.0-beta.2",
"ember-cli-typescript-blueprints": "^2.0.0-beta.1",
"ember-cli-uglify": "2.1.0",
"ember-cli-yuidoc": "^0.8.8",
"ember-decorators": "^3.0.0",
Expand All @@ -108,7 +119,8 @@
"mocha-only-detector": "1.0.0",
"prettier": "^1.14.3",
"rimraf": "^2.6.2",
"rsvp": "^4.8.4"
"rsvp": "^4.8.4",
"typescript": "~3.1.3"
},
"engines": {
"node": ">= 6.0.0"
Expand Down
16 changes: 16 additions & 0 deletions tests/dummy/app/config/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default config;

/**
* Type declarations for
* import config from './config/environment'
*
* For now these need to be managed by the developer
* since different ember addons can materialize new entries.
*/
declare const config: {
environment: any;
modulePrefix: string;
podModulePrefix: string;
locationType: string;
rootURL: string;
};
55 changes: 55 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"compilerOptions": {
"target": "es2017",
"allowJs": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I always approach a large TS conversion by going through the following process:

  1. Making a first pass w/ "noImplicitAny": false across the whole codebase. The main goal is to convert each file to .ts. This involves dealing with the subset of JS that TS is unhappy with (i.e., ES6 classes that don't state their member field types up front, extra stuff pinned onto functions, etc...)
  2. Set "noImplicitAny": true and make all the anys explicit instead of implicit
  3. Get rid of any remaining anys as possible

Starting out with strict TS config will result in a lot of thrash, as new type-checking issues surface in waves (i.e., a commit that improves types in file B reveals type-checking failures in file A -- over and over and over)

"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noEmitOnError": false,
"noEmit": true,
"inlineSourceMap": true,
"inlineSources": true,
"baseUrl": ".",
"module": "es6",
"paths": {
"dummy/tests/*": [
"tests/*"
],
"dummy/*": [
"tests/dummy/app/*",
"app/*"
],
"ember-data": [
"addon"
],
"ember-data/*": [
"addon/*"
],
"ember-data/test-support": [
"addon-test-support"
],
"ember-data/test-support/*": [
"addon-test-support/*"
],
"*": [
"types/*"
]
}
},
"include": [
"app/**/*",
"addon/**/*",
"tests/**/*",
"types/**/*",
"test-support/**/*",
"addon-test-support/**/*"
]
}
1 change: 1 addition & 0 deletions types/dummy/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

is this file supposed to be empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's added by default, yeah

Loading