TypeScript Haɗin kai tare da Angular, React da Vue.js: Kanfigareshan da fa'idodi a Ci gaban Aikace-aikacen Yanar Gizo

Gabatarwa

A cikin duniyar zamani na ci gaban aikace-aikacen yanar gizo, ta yin amfani TypeScript da mashahuran ginshiƙai kamar Angular, React, kuma Vue.js ya zama al'ada mai mahimmanci. TypeScript yana ba da duban nau'in a tsaye, yana ba da gudummawa ga haɓaka ƙarin lambobi masu ƙarfi da sassauƙa. Bisa ga wannan, wannan labarin yana ba da cikakken jagora kan yadda ake tsarawa TypeScript da kuma amfani da fa'idodinsa a cikin haɓaka aikace-aikacen yanar gizo tare da waɗannan shahararrun tsarin.

 

Ana daidaitawa TypeScript tare da Angular

Amfani Angular CLI don ƙirƙirar TypeScript aiki

Angular CLI yana ba da hanya mai sauri da sauƙi don ƙirƙirar Angular aikin da aka riga aka tsara tare da TypeScript. Kawai gudanar da umarni mai zuwa don ƙirƙirar sabon aiki:

ng new my-app --defaults

Yana daidaitawa tsconfig.json

Fayil na tsconfig.json yana ba ku damar tsara TypeScript saituna a cikin Angular aikin ku. Misali, zaku iya saita fayil ɗin tsconfig.json kamar haka:

{  
  "compilerOptions": {  
    "target": "es2017",  
    "module": "es2020",  
    "strict": true  
  }  
}  

Yin amfani da nau'in bincike na tsaye da goyan bayan IntelliSense lokacin haɓaka tare Angular da TypeScript

Misali: Gina wani Angular component tare da TypeScript:

import { Component } from '@angular/core';  
  
@Component({  
  selector: 'app-example',  
  template: `  
    <h1>{{ greeting }}</h1>  
  `  
})  
export class ExampleComponent {  
  greeting: string = 'Hello, TypeScript!';  
}  

 

Ana daidaitawa TypeScript tare da React

Amfani da Ƙirƙiri React App tare da TypeScript

Ƙirƙiri React App sanannen kayan aiki ne don ƙirƙirar React ayyuka. Kuna iya ƙirƙirar sabon aiki tare TypeScript da gudanar da umarni mai zuwa:

npx create-react-app my-app --template typescript

Shigar da TypeScript ɗakunan karatu na tallafi a ciki React

Shigar da fakitin don tabbatar da iya fahimta da ba da taimako irin na lambar ku. @types/react @types/react-dom TypeScript React

Yin amfani da nau'in sanarwa na nau'in nau'in nau'in nau'in nau'in nau'in nau'in nau'in nau'in nau'in nau'in nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i nau'i)) da kuma bincika nau'in nau'in nau'i a cikin React lambar

Misali: Gina wani React sashi da TypeScript:

import React from 'react';  
  
interface Props {  
  name: string;  
}  
  
const Greeting: React.FC<Props> =({ name }) => {  
  return <h1>Hello, {name}!</h1>;  
};  
  
export default Greeting;  

 

Ana daidaitawa TypeScript tare da Vue.js

Amfani Vue CLI da ƙirƙirar Vue.js aikin tare da TypeScript

Vue CLI yana ba da samfuran aikin da aka riga aka tsara don ƙirƙirar Vue.js ayyuka tare da TypeScript. Kawai gudanar da umarni mai zuwa:

vue create my-app

Sannan, zaɓi samfuri mai goyan bayan TypeScript.

Yin amfani da TypeScript fasali a cikin Vue.js ci gaba

Misali: Gina a Vue component tare da TypeScript:

<template>  
  <h1>{{ greeting }}</h1>  
</template>  
  
<script lang="ts">  
import { Vue, Component } from 'vue-property-decorator';  
  
@Component  
export default class GreetingComponent extends Vue {  
  greeting: string = 'Hello, TypeScript!';  
}  
</script>  

 

Amfanin TypeScript ci gaban aikace-aikacen yanar gizo

  • Binciken nau'in a tsaye yana taimakawa gano kurakurai da wuri kuma yana tabbatar da daidaiton lamba.
  • IntelliSense da taimako na hankali suna haɓaka yawan aiki da rage lokacin yin kuskure.
  • Lambar ta zama mafi kiyayewa kuma tana da ƙarfi tare da yin amfani da nau'in sanarwa da TypeScript fasali.
  • Haɗin kai mara kyau tare da shahararrun kayan aikin haɓakawa da ɗakunan karatu kamar masu tarawa, debuggers, da manajan fakiti.

 

Kammalawa

A cikin wannan labarin, mun ba da cikakken jagora kan daidaitawa TypeScript da amfani da fa'idodin sa yayin aiki tare da shahararrun tsarin gidan yanar gizo kamar Angular, React  da Vue.js. Ta amfani da TypeScript, zaku iya haɓaka sassauci, rage kurakurai, da haɓaka aiki a cikin haɓaka aikace-aikacen gidan yanar gizon ku.

 

Tare da wannan jagorar, zaku sami cikakkiyar fahimtar yadda ake daidaitawa TypeScript da yin amfani da fa'idodinsa a cikin haɓaka aikace-aikacen gidan yanar gizo tare da shahararrun tsarin kamar Angular, React, da Vue.js.