728x90
λ°μν
const cache = {};
const add = (id: string, value: string) => {
cache[id] = value;
};
const remove = (id: string) => {
delete cache[id];
};
cache κ°μ²΄μλ λμ μΌλ‘ ν€κ° μΆκ°λκ³ , μμ λ μ μλ€.
1. Record μ¬μ©νκΈ°
const cache: Record<string, string> = {}
Recordμ 첫λ²μ§Έ μΈμμλ keyμ νμ , λλ²μ§Έμλ valueμ νμ μ μ§μ νλ€.
Record<Keys, Type>
κ°μ²΄μ ν€κ° Keys, κ°μ Typeμ μ§μ νμ¬ κ°μ²΄ νμ μ λ§λ€ μ μλ€.
2. index νμ μ§μ
const cache: {
[id: string]: string
} = {};
μΈν°νμ΄μ€ λλ νμ μ¬μ©
interface Cache {
[id: string]: string
}
type Cache {
[id: string]: string
}
728x90
λ°μν
'π©βπ€ νλ‘ νΈμλ > typescript' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
TS2339: Property 'reset' does not exist on type 'EventTarget'. (0) | 2023.01.10 |
---|---|
Property 'Authorization' does not exist on type 'AxiosHeaders' (0) | 2023.01.08 |