1th School Project : Software Engineering__20210427 ts export,import class not found
Status Quo
I am importing 'reportUser' class
from 'index.ts'
to 'community.ts'
community.ts
import { reportUser } from "./domainModels/index"
const reportComments = class extends reportUser{
constructor(divClassName : string, targetClassName : string){
// constructor(){
super()
if (this.inputError(divClassName)) throw 'Error'
if (this.inputError(targetClassName)) throw 'Error'
this.contentsDiv = document.querySelector(`.${divClassName}`)
this.targetClassName = targetClassName
// super(commentId,className)
}
report(){
return;
}
clickHandler(e:any):void{
if(e.target.classList.contains(this.targetClassName))
this.executeClickHandler()
}
connectClickHandler(className : string) : void {
this.contentsDiv!.addEventListener('click',this.clickHandler)
}
executeClickHandler() : void {throw 'override'}
}
index.ts
export const reportUser = class {
contentId : number = 0 ;
targetClassName : string = '';
contentsDiv : HTMLDivElement | null = new HTMLDivElement() ;
constructor(){
// constructor(contentId : number, className : string){
// contentId : 댓글 혹은 게시글 id
// this.contentsDiv = document.querySelector(`.${className}`)
}
inputError(className : string):boolean{return !document.querySelector(`.${className}`) ? true : false}
report() : void {throw 'override' }
sampleClickHandler(className : string, e : any ) : void {throw 'override'}
connectClickHandler(className : string, e : any ) : void {throw 'override'}
executeClickHandler() : void {throw 'override'}
}
Problem
after applying 'community.js' to html file
below error occurs
Solution 1_1
in 'community.js'
import { reportUser } from "./domainModels/index"
to
import { reportUser } from "./domainModels/index.js"
Solution 1_2
ts.config.json
That is,
you have to explicitly mention 'js' in the end
why ?
we are compiliting ts code into js
and the browser will import 'JS' files not 'TS' files
that is why we have to explicitly tell 'JS' without omitting it
link
https://www.youtube.com/watch?v=EpOPR03z4Vw
Author And Source
이 문제에 관하여(1th School Project : Software Engineering__20210427 ts export,import class not found), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dhsys112/1th-School-Project-Software-Engineering20210427-ts-exportimport-class-not-found저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)