An Warware: Yin watsi da Kurakurai na TypeScript a js na gaba

Tabbas, ga cikakken labarin da ke bayanin yadda ake watsi da kurakuran rubutu a cikin Next.js:

Next.js, tsarin tushen amsawa, mafita ce ta tsayawa ษ—aya don haษ“aka ingantaccen aikace-aikacen gidan yanar gizo tare da ฦ™warewar mai amfani mara kyau. ฦŠaya daga cikin mahimman fa'idodi na amfani da Next.js shine kuma yana goyan bayan TypeScript, mashahurin babban saiti na JavaScript. Lokaci-lokaci, yayin haษ“akawa, TypeScript yana jefa kurakurai game da nau'ikan da ฦ™ila za mu buฦ™aci yin watsi da su. Bari mu bincika yadda ake kewaye waษ—annan al'amuran.Lura: TypeScript kayan aiki ne mai ฦ™arfi, yin watsi da kurakuran TypeScript ya kamata a yi kawai lokacin da ka tabbata waษ—annan kurakuran ba za su shafi aikin aikace-aikacenku ko amincin ku ba.

##

Fahimtar Kurakurai Na Rubutun a Next.js

ฦ˜arfin TypeScript ya ta'allaka ne ga ikonsa na tilasta yin duba nau'in, fasalin da ba shi da JavaScript. Koyaya, ana iya samun lokatai lokacin da kuke buฦ™atar kashe takamaiman nau'in duba wani ษ“angaren lambar ku. Waษ—annan wuraren da ba a kula da su ba da gangan ne kuma, idan aka yi amfani da su ba daidai ba, na iya haifar da yuwuwar kurakurai a cikin aikin ku. Wannan yana ba da sassauci ga masu haษ“akawa inda suke da iko akan duba nau'in.

// @ts-ignore
let myData: any = "This could be anything";

Snippet lambar TypeScript da ke sama tana kwatanta umarnin @ts-yi watsi da umarnin wanda ke gaya wa TypeScript don murkushe kuskuren da ke faruwa akan layi na gaba.

##

Maganin Yin watsi da Kurakurai Na TypeScript a Next.js

Ma'amala da kurakuran TypeScript na iya zama batun sassauฦ™an zaษ“in coding maimakon tsangwama. Akwai hanyoyi don gaya wa TypeScript kada ku damu da takamaiman layi ko toshe lambar, kuma ga yadda mutum zai iya cimma ta:

// @ts-ignore
let ignoreThisError: any = "This error will be ignored by TypeScript";

Wannan shine amfani da umarnin @ts-yi watsi da kurakurai a cikin TypeScript a cikin aikin mu na Next.js. Koyaya, lura cewa @ts-ignore yana ba ku damar yin watsi da kowane kurakurai na TypeScript akan layin da ke ฦ™asa inda aka ayyana shi. Don haka, mafita ce mai layi ษ—aya don yin watsi da Kurakurai na TypeScript.

##

Fahimtar @ts-igore da sauran Dokoki masu alaฦ™a

Baya ga @ts-ignore, TypeScript kuma yana ba da wasu umarni don ฦ™arin al'amura masu rikitarwa. Wasu daga cikinsu sune @ts-nocheck, wanda ke kashe nau'in bincikar duk fayil ษ—in, da @ts-expect-error, da ake amfani da su lokacin da kuke gwada lambar ku kuma kuna tsammanin kuskuren TypeScript.

  • @ts-nocheck: Ana amfani da shi don yin watsi da duk kurakurai a cikin fayil na yanzu
  • @ts-expect-error: Ana amfani da shi kawai idan kuna tsammanin kuskure amma kuna buฦ™atar gyarawa nan gaba.
  • // @ts-nocheck
    let data1: any = "All errors in this file will be ignored";
    
    // @ts-expect-error
    let data2: any;
    

    Yin watsi da kurakuran TypeScript a cikin Next.js ko kowane aikace-aikacen TypeScript ya kamata koyaushe ya zama makoma ta ฦ™arshe. Ko da yake waษ—annan umarni sun wanzu, ana ba da shawarar amfani da su kaษ—an don kiyaye mutunci da nau'in amincin lambar lambar ku. Koyaushe tuna, Kuskuren TypeScript shawarwari ne don inganta lambar mu ba cikas ba.

Shafi posts:

Leave a Comment