There is a small issue with Deno:
This here works:
export default class myClass{
get(path: string){
console.log(path)
}
}
but this here doesn't:
export default class myClass{
constructor(){
this.data = {}
}
get(path: string){
console.log(path)
}
}
Does Deno only support constructor function or what's up?
What do you expect it to do and what happens instead? constructor has special meaning in the context of classes: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor
What do you expect it to do and what happens instead?
constructorhas special meaning in the context of classes: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor
I want to import a class from a file into another file, but this doesn't work.
I want to import a class from a file into another file, but this doesn't work.
What doesn't work? You are not providing sufficient information, which leads us to guessing at what you are doing. I can only assume you have the code example you provided in a TypeScript file. If that is the case, you haven't defined a property of data and all TypeScript in Deno defaults to strict mode, therefore the TypeScript compiler is saying you aren't properly typing your class. If my crystal ball is correct then this should fix the problem:
export default class myClass{
data: any;
constructor(){
this.data = {}
}
get(path: string){
console.log(path)
}
}
This isn't a problem with Deno.
If my random guess at what you are trying to do is wrong, please provide more details.
@kitsonk Tank you for the answer, but my crystal ball didn't tell me which informations are needed.
I guess I need to work on TypeScript a little. I can also be unfriendly :)
@kitsonk Tank you for the answer, but my crystal ball didn't tell me which informations are needed.
I guess I need to work on TypeScript a little. I can also be unfriendly :)
Tip is to get a good "linter"/helper in your IDE. I recommend TypeScript Hero for VS Code.