-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Closed
Labels
Description
Version
3.2.1
Reproduction link
https://github.com/BurnashevDmitry/date_error_vue_complier
Steps to reproduce
Example
src/CargoService.ts
interface ICargo {
name: string;
createdAt: Date;
price: number;
}
export class Cargo implements ICargo {
name: string;
price: number;
createdAt: Date;
constructor(name = '', price = 0) {
this.name = name;
this.price = price;
this.createdAt = new Date();
}
}
export default class CargoService {
static info(cargoData: Cargo): void {
console.log(cargoData);
}
}App.vue
<script lang="ts">
import { defineComponent, ref } from 'vue';
import CargoService, { Cargo } from './CargoService';
export default defineComponent({
data() {
return {
cargo: new Cargo('first', 100),
};
},
methods: {
info() {
CargoService.info(this.cargo);
},
},
});
</script>Error
src/App.vue:20:25
TS2345: Argument of type '{ name: string; price: number; createdAt: { toString: () => string; toDateString: () => string; toTimeString: () => string; toLocaleString: { (): string; (locales?: string | string[] | undefined, options?: DateTimeFormatOptions | undefined): string; }; ... 39 more ...; getVarDate: () => VarDate; }; }' is not assignable to parameter of type 'Cargo'.
Types of property 'createdAt' are incompatible.
Property '[Symbol.toPrimitive]' is missing in type '{ toString: () => string; toDateString: () => string; toTimeString: () => string; toLocaleString: { (): string; (locales?: string | string[] | undefined, options?: DateTimeFormatOptions | undefined): string; }; ... 39 more ...; getVarDate: () => VarDate; }' but required in type 'Date'.
18 | methods: {
19 | info() {
> 20 | CargoService.info(this.cargo);
| ^^^^^^^^^^
21 | },
22 | },
23 | });
What is expected?
All works fine
What is actually happening?
Property '[Symbol.toPrimitive]' is missing in type Data
Similar to vuejs/composition-api#279
danielhgasparin, baronkoko, pochingliu131, razorness, hideak and 4 more