Skip to content

Commit

Permalink
Typescript ^4 (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch authored Aug 31, 2022
1 parent bd05164 commit ad1f4e4
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 142 deletions.
135 changes: 52 additions & 83 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"test": "npm run build && testem ci -f testem.js",
"lint": "prettier 'src/**/*.{js,ts}' --check && eslint 'src/**/*.{js,ts}'",
"format": "prettier 'src/**/*.{js,ts}' --write",
"typecheck": "tsc",
"clean": "rm -rf dist",
"build": "rollup -c",
"build:docs": "typedoc",
Expand Down Expand Up @@ -74,8 +75,8 @@
"saucie": "^3.3.3",
"testem": "^3.9.0",
"tslib": "^2.4.0",
"typedoc": "^0.22.18",
"typescript": "^3.9.10"
"typedoc": "^0.23.12",
"typescript": "^4.8.2"
},
"prettier": {
"arrowParens": "avoid",
Expand Down
1 change: 1 addition & 0 deletions src/js/editor/post/post-inserter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Visitor {
visit(node: PostNode) {
let method = node.type
assertType<typeof method & keyof this>(`Cannot visit node of type ${node.type}`, method, method in this)
// @ts-ignore: TODO: this isn't safely callable for all types
this[method](node as any)
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/models/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function isCardSection(section: {}): section is Card {

export type CardPayload = {}

export default class Card<T = CardPayload> extends Section {
export default class Card<T extends {} = CardPayload> extends Section {
name: string
payload: T
builder!: PostNodeBuilder
Expand Down
2 changes: 2 additions & 0 deletions src/js/models/list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class ListItem extends Markerable {
isListItem = true
isNested = true
section: Section | null = null
// @ts-ignore: TODO: remove ignore
parent!: ListSection

constructor(tagName: string, markers: Markuperable[] = []) {
Expand All @@ -38,6 +39,7 @@ export default class ListItem extends Markerable {
return this._redistributeMarkers(beforeSection, afterSection, marker, offset)
}

// @ts-ignore: TODO: remove ignore
get post() {
return expect(this.section, 'expected list item to have section').post
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/parsers/mobiledoc/0-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class MobiledocParser {

return post
} catch (e) {
assert(`Unable to parse mobiledoc: ${e.message}`, false)
assert(`Unable to parse mobiledoc: ${e instanceof Error ? e.message : ''}`, false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/parsers/mobiledoc/0-3-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class MobiledocParser {

return post
} catch (e) {
assert(`Unable to parse mobiledoc: ${e.message}`, false)
assert(`Unable to parse mobiledoc: ${e instanceof Error ? e.message : ''}`, false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/parsers/mobiledoc/0-3-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class MobiledocParser {

return post
} catch (e) {
assert(`Unable to parse mobiledoc: ${e.message}`, false)
assert(`Unable to parse mobiledoc: ${e instanceof Error ? e.message : ''}`, false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/parsers/mobiledoc/0-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class MobiledocParser {

return post
} catch (e) {
assert(`Unable to parse mobiledoc: ${e.message}`, false)
assert(`Unable to parse mobiledoc: ${e instanceof Error ? e.message : ''}`, false)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/js/utils/merge.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function mergeWithOptions<A, B, O>(original: A, updates: B, options?: O) {
function mergeWithOptions<A extends {}, B, O>(original: A, updates: B, options?: O) {
return Object.assign(original, updates, options)
}

/**
* Merges properties of one object into another
* @private
*/
function merge<A, B>(original: A, updates: B) {
function merge<A extends {}, B>(original: A, updates: B) {
return mergeWithOptions(original, updates)
}

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/utils/assert-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ test('#throws a MobiledocError when conditional is false', assert => {
mobiledocAssert('The message', false)
} catch (e) {
assert.ok(true, 'caught error')
assert.equal(e.message, 'The message')
assert.equal(e instanceof Error ? e.message : '', 'The message')
assert.ok(e instanceof MobiledocError, 'e instanceof MobiledocError')
}
})

Loading

0 comments on commit ad1f4e4

Please sign in to comment.