Skip to content

Commit c243b11

Browse files
Merge pull request microsoft#40 from Microsoft/definiteAssignments
Use definite assignment assertions in class components.
2 parents 0b060e5 + 299ccb3 commit c243b11

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

Diff for: README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,11 @@ import { Vue, Component, Prop } from "vue-property-decorator";
443443

444444
@Component
445445
export default class HelloDecorator extends Vue {
446-
@Prop() name: string;
447-
@Prop() initialEnthusiasm: number;
446+
@Prop() name!: string;
447+
@Prop() initialEnthusiasm!: number;
448+
448449
enthusiasm = this.initialEnthusiasm;
450+
449451
increment() {
450452
this.enthusiasm++;
451453
}
@@ -454,6 +456,7 @@ export default class HelloDecorator extends Vue {
454456
this.enthusiasm--;
455457
}
456458
}
459+
457460
get exclamationMarks(): string {
458461
return Array(this.enthusiasm + 1).join('!');
459462
}
@@ -463,6 +466,8 @@ export default class HelloDecorator extends Vue {
463466
Instead of using `Vue.extend` to define our component, we create a class extending `Vue` and decorate it using the `@Component` decorator from the `vue-class-component` package (which was re-exported from the `vue-property-decorator` package).
464467

465468
Properties are defined by prefixing instance variables with the `@Prop()` decorator from the `vue-property-decorator` package.
469+
Because the `--strictPropertyInitialization` option is on, we need to tell TypeScript that Vue will initialize our properties by appending a `!` to them.
470+
This tells TypeScript "hey, relax, someone else is going to assign this property a value."
466471

467472
Regular instance variables, such as `enthusiasm` in our example, are automatically made available for data binding to the template, just as if they had been defined in the `data` field.
468473
Note that all variables must be set to a value other than `undefined` for the binding to work.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"devDependencies": {
2424
"css-loader": "^0.28.1",
2525
"ts-loader": "^2.0.3",
26-
"typescript": "^2.3.2",
26+
"typescript": "^2.7.2",
2727
"vue-loader": "^12.0.3",
2828
"vue-template-compiler": "^2.5.2",
2929
"webpack": "^2.5.0"

Diff for: src/components/HelloDecorator.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { Vue, Component, Prop } from "vue-property-decorator";
1313

1414
@Component
1515
export default class HelloDecorator extends Vue {
16-
@Prop() name: string;
17-
@Prop() initialEnthusiasm: number;
16+
@Prop() name!: string;
17+
@Prop() initialEnthusiasm!: number;
1818

1919
enthusiasm = this.initialEnthusiasm;
2020

Diff for: yarn.lock

+27-12
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,10 @@ reduce-function-call@^1.0.1:
20402040
dependencies:
20412041
balanced-match "^0.4.2"
20422042

2043+
reflect-metadata@^0.1.10:
2044+
version "0.1.12"
2045+
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.12.tgz#311bf0c6b63cd782f228a81abe146a2bfa9c56f2"
2046+
20432047
regenerate@^1.2.1:
20442048
version "1.3.2"
20452049
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.2.tgz#d1941c67bad437e1be76433add5b385f95b19260"
@@ -2382,9 +2386,9 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
23822386
version "0.14.5"
23832387
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
23842388

2385-
typescript@^2.3.2:
2386-
version "2.3.2"
2387-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.2.tgz#f0f045e196f69a72f06b25fd3bd39d01c3ce9984"
2389+
typescript@^2.7.2:
2390+
version "2.7.2"
2391+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
23882392

23892393
uglify-js@^2.8.5:
23902394
version "2.8.22"
@@ -2461,6 +2465,10 @@ [email protected]:
24612465
dependencies:
24622466
indexof "0.0.1"
24632467

2468+
vue-class-component@^6.0.0:
2469+
version "6.2.0"
2470+
resolved "https://registry.yarnpkg.com/vue-class-component/-/vue-class-component-6.2.0.tgz#7adb1daa9a868c75f30f97f33f4f1b94aee62089"
2471+
24642472
vue-hot-reload-api@^2.1.0:
24652473
version "2.1.0"
24662474
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.1.0.tgz#9ca58a6e0df9078554ce1708688b6578754d86de"
@@ -2483,9 +2491,16 @@ vue-loader@^12.0.3:
24832491
vue-style-loader "^3.0.0"
24842492
vue-template-es2015-compiler "^1.2.2"
24852493

2486-
"vue-router@https://github.com/DanielRosenwasser/vue-router#01b8593cf69c2a5077df45e37e2b24d95bf35ce3":
2487-
version "2.3.0"
2488-
resolved "https://github.com/DanielRosenwasser/vue-router#01b8593cf69c2a5077df45e37e2b24d95bf35ce3"
2494+
vue-property-decorator@^6.0.0:
2495+
version "6.0.0"
2496+
resolved "https://registry.yarnpkg.com/vue-property-decorator/-/vue-property-decorator-6.0.0.tgz#bb651b293542e31db0d24f36f4b0250ef08d8515"
2497+
dependencies:
2498+
reflect-metadata "^0.1.10"
2499+
vue-class-component "^6.0.0"
2500+
2501+
vue-router@^3.0.1:
2502+
version "3.0.1"
2503+
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9"
24892504

24902505
vue-style-loader@^3.0.0:
24912506
version "3.0.1"
@@ -2494,9 +2509,9 @@ vue-style-loader@^3.0.0:
24942509
hash-sum "^1.0.2"
24952510
loader-utils "^1.0.2"
24962511

2497-
vue-template-compiler@2.2.1:
2498-
version "2.2.1"
2499-
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.2.1.tgz#ca5e43db50dc6e761e3c1296313de33091783511"
2512+
vue-template-compiler@^2.5.2:
2513+
version "2.5.16"
2514+
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.16.tgz#93b48570e56c720cdf3f051cc15287c26fbd04cb"
25002515
dependencies:
25012516
de-indent "^1.0.2"
25022517
he "^1.1.0"
@@ -2505,9 +2520,9 @@ vue-template-es2015-compiler@^1.2.2:
25052520
version "1.5.2"
25062521
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.2.tgz#a0a6c50c941d2a4abda963f2f42c337ac450ee95"
25072522

2508-
"vue@https://github.com/DanielRosenwasser/vue#540a38fb21adb7a7bc394c65e23e6cffb36cd867":
2509-
version "2.2.1"
2510-
resolved "https://github.com/DanielRosenwasser/vue#540a38fb21adb7a7bc394c65e23e6cffb36cd867"
2523+
vue@^2.5.2:
2524+
version "2.5.16"
2525+
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085"
25112526

25122527
watchpack@^1.3.1:
25132528
version "1.3.1"

0 commit comments

Comments
 (0)