Mulai 29 April 2025, model Gemini 1.5 Pro dan Gemini 1.5 Flash tidak tersedia di project yang belum pernah menggunakan model ini, termasuk project baru. Untuk mengetahui detailnya, lihat
Versi dan siklus proses model .
Kirim masukan
Migrasi TypeScript
bookmark_border bookmark
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menerjemahkan JavaScript ke TypeScript.
Anda dapat membuat kueri model secara langsung dan menguji hasil yang ditampilkan saat menggunakan
parameter value yang berbeda dengan Konsol Cloud, atau dengan memanggil
Vertex AI API secara langsung.
Petunjuk sistem
Anda adalah developer ahli dalam JavaScript dan TypeScript. Saya akan memberikan file JavaScript untuk diterjemahkan ke TypeScript. Jangan memberikan penjelasan kode. Jangan memberikan saran atau membuat perubahan fungsi apa pun pada kode.
Konversi kode ini ke TypeScript. Pastikan untuk terus menggunakan kata kunci get
dan set
serta menggunakan antarmuka sesuai kebutuhan.
import { validateNonNegative , validateDiscount } from './validationHelpers' ;
class Product {
private _name : string ;
private _price : number ;
private _category : string ;
private _quantity : number ;
private _manufacturer : string ;
private _sku : string ;
private _discount : number ;
constructor ( name : string , price : number , category : string , quantity : number , manufacturer : string , sku : string , discount : number = 0 ) {
this . _name = name ;
this . _price = price ;
this . _category = category ;
this . _quantity = quantity ;
this . _manufacturer = manufacturer ;
this . _sku = sku ;
this . _discount = discount ;
}
get name () : string { return this . _name ; }
get price () : number { return this . _price ; }
get category () : string { return this . _category ; }
get quantity () : number { return this . _quantity ; }
get manufacturer () : string { return this . _manufacturer ; }
get sku () : string { return this . _sku ; }
get discount () : number { return this . _discount ; }
set name ( newName : string ) { this . _name = newName ; }
set price ( newPrice : number ) {
validateNonNegative ( newPrice , 'Price' );
this . _price = newPrice ;
}
set category ( newCategory : string ) { this . _category = newCategory ; }
set quantity ( newQuantity : number ) {
validateNonNegative ( newQuantity , 'Quantity' );
this . _quantity = newQuantity ;
}
set manufacturer ( newManufacturer : string ) { this . _manufacturer = newManufacturer ; }
set sku ( newSku : string ) { this . _sku = newSku ; }
set discount ( newDiscount : number ) {
validateDiscount ( newDiscount );
this . _discount = newDiscount ;
}
getProductDetails () : string {
const discountedPrice = this . _price * ( 1 - this . _discount / 100 );
return `Product: ${ this . _name } , Price: $ ${ discountedPrice . toFixed ( 2 ) } , Category: ${ this . _category } , Quantity: ${ this . _quantity } , Manufacturer: ${ this . _manufacturer } , SKU: ${ this . _sku } , Discount: ${ this . _discount } %` ;
}
}
export default Product ;
Respons
import { validateNonNegative , validateDiscount } from './validationHelpers' ;
interface ProductInterface {
name : string ;
price : number ;
category : string ;
quantity : number ;
manufacturer : string ;
sku : string ;
discount : number ;
getProductDetails () : string ;
}
class Product implements ProductInterface {
private _name : string ;
private _price : number ;
private _category : string ;
private _quantity : number ;
private _manufacturer : string ;
private _sku : string ;
private _discount : number ;
constructor ( name : string , price : number , category : string , quantity : number , manufacturer : string , sku : string , discount : number = 0 ) {
this . _name = name ;
this . _price = price ;
this . _category = category ;
this . _quantity = quantity ;
this . _manufacturer = manufacturer ;
this . _sku = sku ;
this . _discount = discount ;
}
get name () : string { return this . _name ; }
get price () : number { return this . _price ; }
get category () : string { return this . _category ; }
get quantity () : number { return this . _quantity ; }
get manufacturer () : string { return this . _manufacturer ; }
get sku () : string { return this . _sku ; }
get discount () : number { return this . _discount ; }
set name ( newName : string ) { this . _name = newName ; }
set price ( newPrice : number ) {
validateNonNegative ( newPrice , 'Price' );
this . _price = newPrice ;
}
set category ( newCategory : string ) { this . _category = newCategory ; }
set quantity ( newQuantity : number ) {
validateNonNegative ( newQuantity , 'Quantity' );
this . _quantity = newQuantity ;
}
set manufacturer ( newManufacturer : string ) { this . _manufacturer = newManufacturer ; }
set sku ( newSku : string ) { this . _sku = newSku ; }
set discount ( newDiscount : number ) {
validateDiscount ( newDiscount );
this . _discount = newDiscount ;
}
getProductDetails () : string {
const discountedPrice = this . _price * ( 1 - this . _discount / 100 );
return `Product: ${ this . _name } , Price: $ ${ discountedPrice . toFixed ( 2 ) } , Category: ${ this . _category } , Quantity: ${ this . _quantity } , Manufacturer: ${ this . _manufacturer } , SKU: ${ this . _sku } , Discount: ${ this . _discount } %` ;
}
}
export default Product ;
Model:
gemini-1.5-flash-002
Suhu:
0,2
Token output maks:
8192
TopK:
40,0
TopP:
0,95
Kirim masukan
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0 , sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0 . Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers . Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-26 UTC.
Ada masukan untuk kami?
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-26 UTC."],[],[]]