일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- async
- reactnative
- 배열중복요소제거
- extends
- 상속
- interface
- set
- 스크롤이벤트
- 슬라이딩윈도우
- err_connection_refused
- mainapplication.kt
- npm에러
- generic
- array
- 안드로이드빌드에러
- map
- 타입스크립트
- materialicons
- forwardref type
- TS
- react
- javascript
- app:compiledebugkotlin
- Filter
- reactnative error
- app.post
- Spring
- 이진탐색
- 리액트네이티브아이콘
- Next.js
- Today
- Total
목록Html_css_js (55)
rhanziy
원래는 intersection type이라고 & 연산자를 통해 두 타입을 만족하는 코드를 짤 수 있었다. // intersection type // 두 타입을 만족하는 타입을 뜻함 type Animal2 = { name : string } type Cat2 = { age : number } & Animal2 let munzi :Cat2 = { name : 'munzi', age : 10 } 그런데 interface로도 가능. extends 하면 되니까. interface Student{ name : string; } interface Student{ score : number; } interface Teacher extends Student { age : number } let 학생 :Student = ..
object 뽑는 기계 class에도 타입을 지정해줄 수 있다. ES6 신문법에서는 constructor함수를 쓰면 되는데, this.어쩌구를 쓰고 싶으면 미리 어쩌구를 필드값으로 지정해 줘야함. class CarInfo { model : string; price : number; constructor(a:string, b:number){ this.model = a, this.price = b } tax() :number{ return this.price * 0.1; } } let car = new CarInfo('소나타', 3000); console.log(car); // { model : '소나타', price : 3000 } console.log(car.tax()); // 300 필드값으로 mode..
서버에 해당 글 삭제 요청을 하기위한 delete기능. html에서는 불가능하다. form의 method는 GET 과 POST만 가능하기때문에 어떻게 구현하면 좋을까나 1. method-override 라이브러리 이용(node.js) 2. JavaScript AJAX 이용 jQuery라이브러리로 2번 방법을 써보자. AJAX란 ? 새로고침 없이 서버랑 통신할 수 있게 도와주는 JS문법. 제이쿼리 cdn먼저 복붙하고... ajax 기본문법. // list.ejs 원하는 기능은 게시물에 맞는 삭제버튼을 누를 때 해당 게시물을 삭제하는 기능이기 때문에, button태그에 data-id 속성으로 id값을 부여해준다. // list.ejs . 할일 제목 : 할일 마감 날짜 : 삭제 그리고 삭제버튼을 버튼을 누르면..
type 작명 = (파라미터 type) => return type; 으로 함수의 alias타입을 지정해준다. type Func3 = (a :string) => number; let func3 :Func3 = (a) => { return 10;} 이해하기 쉽게 예시를 들어보면 type UserInfo = { name : string, age : number, plusOne : (a:number) => number, changeName : () => void } let userInfo :UserInfo = { name : 'kim', age : 30, plusOne(a){ return a + 1; }, changeName : () => { console.log('안녕'); } } 조금 복잡하지만 함수의 al..
const보다 더 엄격한 값 지정이라고 생각하면 된다. let 이름 :123; let 나 : '30살' | '백수'; 이러면 무조건 이름엔 123이 들어가야하고, 나 라는 변수에는 30살 or 백수라는 값만 넣을 수 있다. function testFunction(hand :'가위'|'바위'|'보') :('가위'|'바위'|'보')[]{ console.log(hand); return [ '보' ]; } testFunction('가위'); testFunction 함수의 파라미터에는 '가위' or '바위' or '보' 라는 문자만 들어올 수 있고, return 값도 동일. 그럼 obj.key의 값을 파라미터로 사용하고 싶으면!!! var data = { name : 'kim' } as const // 1. ob..
type 키워드를 써서 가독성과 확장성을 높일 수 있다. 간단쓰 type Animal = string | number | undefined; let animal :Animal = 'cat'; // obj일 때 type Animal = { name :string, age :number } let 동물 :Animal = { name : 'munzi', age : 10 } const 변수는 등호할당만 막아지는데, 오브젝트 자료형일 경우 아래와 같이 실수로 수정을 할 수 있음. const 출생지역 = { region : 'seoul' } 출생지역.region = 'busan' 타입스크립트에서는 readonly 기능을 통해 타입스크립트 자체에서 error를 띄워줄 수 있다. type Cat = { readonly..
함수의 파라미터 변수에 union type을 지정해주면 엄격한 타입스크립트에서는 x :number | string 일 때, x + 3 같은 간단한 연산도 안된다. 그럴 때 narrowing으로 타입의 범위를 좁혀준다. function 함수2(x :number | string){ //console.log(x + 3); // union type은 안된다. // if(typeof x === 'number'){ // return console.log(x + 3); // } else { } // type narrowing let array :number[] = []; if(typeof x === 'number') { array[0] = x; } //type assertion (타입 덮어쓰기) // 1. Narro..
자바스크립트는 타입에 관대하기 때문에 큰 프로젝트할 때 예상치 못한 에러나 버그가 발생할 수 있다. 그래서 엄격한 타입룰을 지정해주면서 더 정확한 에러메세지를 얻기위해 타입스크립트를 사용함. 설치 1. 일단 Node.js 최신버전, VScode 에디터오픈 2. 터미널 오픈 후 npm install -g typescript 3. 코드 짤 작업폴더 만들고 에디터에서 오픈 4. 작업폴더에 .ts로 끝나는 파일 만들고 사용시작하면됨. 여기서 .ts 파일은 브라우저에서 알아듣지 못하기 때문에 js파일로 변환작업이 필요한데, 터미널에 tsc -w 를 입력해두면 자동으로 js파일로 변환해준다. 그런데! 여기서 오류가 발생할 것. 아마도 이 시스템에서 스크립트를 실행할 수 없으므로~~ 어쩌구. 해결은 윈도우 파워쉘을 ..