TypeSciprt ile dynamic key tanimlamak

typescript, programming

TypeSciprt ile dynamic key tanimlamak

Typesciprt dilinde dynamic anahtar tanimlamasi icin [key] yapisi kullanilir

Ornek Senaryo

async updateRelevantUrl(pageId: string, publisher: Publisher, url: string) {
		const capitalizedPublisher = publisher.charAt(0).toUpperCase() + publisher.slice(1)
		return await this.notionClient.pages.update({
			page_id: pageId,
			properties: {
				[capitalizedPublisher]: {  // [] seklinde olmasina dikkat edin
					rich_text: [{ type: "text", text: { content: url } }]
				}
			}
		})
	}

Hatali Senaryo

Alttaki senaryoda `capitalizedPublisher` degiskeni kullanilmaz, cunku `key` olarak verilmistir
async updateRelevantUrl(pageId: string, publisher: Publisher, url: string) {
		const capitalizedPublisher = publisher.charAt(0).toUpperCase() + publisher.slice(1)
		return await this.notionClient.pages.update({
			page_id: pageId,
			properties: {
				capitalizedPublisher: {
					rich_text: [{ type: "text", text: { content: url } }]
				}
			}
		})
	}
Zaten `ts` du bunu fark edip farki renkte onermistir

Last updated

© 2024 ~ Yunus Emre Ak ~ yEmreAk