Skip to content

Commit 496817d

Browse files
authored
Merge pull request #140 from Gabrielr2508/translation/guide/typescript-support
docs: translates guides/typescript-support to pt-BR
2 parents da86e9c + 20e6fa1 commit 496817d

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/guide/typescript-support.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
# TypeScript Support
1+
# Suporte ao TypeScript
22

3-
> [Vue CLI](https://cli.vuejs.org) provides built-in TypeScript tooling support.
3+
> O [Vue CLI](https://cli.vuejs.org) fornece ferramentas integradas de suporte ao TypeScript.
44
5-
## Official Declaration in NPM Packages
5+
## Declaração Oficial em Pacotes NPM
66

7-
A static type system can help prevent many potential runtime errors as applications grow, which is why Vue 3 is written in TypeScript. This means you don't need any additional tooling to use TypeScript with Vue - it has first-class citizen support.
7+
Um sistema de tipagem estática pode ajudar à prevenir diversos potenciais erros de _runtime_ conforme as aplicações crescem, é por isso que o Vue 3 é escrito em TypeScript. Isso significa que você não precisa de nenhum ferramental adicional para usar TypeScript com Vue - temos um suporte de primeiro mundo.
88

9-
## Recommended Configuration
9+
## Configuração Recomendada
1010

1111
```js
1212
// tsconfig.json
1313
{
1414
"compilerOptions": {
1515
"target": "esnext",
1616
"module": "esnext",
17-
// this enables stricter inference for data properties on `this`
17+
// isso permite uma inferência mais estrita para propriedades de dados no `this`
1818
"strict": true,
1919
"jsx": "preserve",
2020
"moduleResolution": "node"
2121
}
2222
}
2323
```
2424

25-
Note that you have to include `strict: true` (or at least `noImplicitThis: true` which is a part of `strict` flag) to leverage type checking of `this` in component methods otherwise it is always treated as `any` type.
25+
Observe que você precisa incluir `strict: true` (ou ao menos `noImplicitThis: true`, que é uma parte da _flag_ `strict`) para aumentar a checagem de tipos do `this` em métodos de componentes, caso contrário, será sempre tratado como tipo `any`.
2626

27-
See [TypeScript compiler options docs](https://www.typescriptlang.org/docs/handbook/compiler-options.html) for more details.
27+
Veja a [documentação das opções do compilador TypeScript](https://www.typescriptlang.org/docs/handbook/compiler-options.html) para mais detalhes.
2828

29-
## Development Tooling
29+
## Ferramentas de Desenvolvimento
3030

31-
### Project Creation
31+
### Criação de Projeto
3232

33-
[Vue CLI](https://github.com/vuejs/vue-cli) can generate new projects that use TypeScript. To get started:
33+
O [Vue CLI](https://github.com/vuejs/vue-cli) pode gerar novos projetos que usam TypeScript. Para começar:
3434

3535
```bash
36-
# 1. Install Vue CLI, if it's not already installed
36+
# 1. Instale o Vue CLI, se não estiver instalado
3737
npm install --global @vue/cli
3838

39-
# 2. Create a new project, then choose the "Manually select features" option
39+
# 2. Crie um novo projeto e então escolha a opção "Manually select features"
4040
vue create my-project-name
4141

42-
# If you already have a Vue CLI project without TypeScript, please add a proper Vue CLI plugin:
42+
# Se você já tem um projeto com Vue CLI sem TypeScript, por favor adicione o plugin apropriado:
4343
vue add typescript
4444
```
4545

46-
Make sure that `script` part of the component has TypeScript set as a language:
46+
Certifique-se que a parte `script` do componente tem o TypeScript definido como linguagem:
4747

4848
```html
4949
<script lang="ts">
5050
...
5151
</script>
5252
```
5353

54-
### Editor Support
54+
### Suporte do Editor
5555

56-
For developing Vue applications with TypeScript, we strongly recommend using [Visual Studio Code](https://code.visualstudio.com/), which provides great out-of-the-box support for TypeScript. If you are using [single-file components](./single-file-component.html) (SFCs), get the awesome [Vetur extension](https://github.com/vuejs/vetur), which provides TypeScript inference inside SFCs and many other great features.
56+
Para o desenvolvimento de aplicações Vue com TypeScript, nós recomendamos fortemente o uso do [Visual Studio Code](https://code.visualstudio.com/), que fornece um excelente suporte para o TypeScript. Se você está usando [componentes Single File](./single-file-component.html) (SFCs), obtenha a incrível [extensão Vetur](https://github.com/vuejs/vetur), que provê a inferência do TypeScript dentro de SFCs e muitos outros ótimos recursos.
5757

58-
[WebStorm](https://www.jetbrains.com/webstorm/) also provides out-of-the-box support for both TypeScript and Vue.
58+
O [WebStorm](https://www.jetbrains.com/webstorm/) também fornece um suporte pronto para uso de ambos, TypeScript e Vue.
5959

60-
## Defining Vue components
60+
## Definindo Componentes Vue
6161

62-
To let TypeScript properly infer types inside Vue component options, you need to define components with `defineComponent` global method:
62+
Para permitir ao TypeScript inferir corretamente os tipos dentro das opções do componente Vue, você precisa definir os componentes com o método global `defineComponent`:
6363

6464
```ts
6565
import { defineComponent } from 'vue'
6666

6767
const Component = defineComponent({
68-
// type inference enabled
68+
// inferência de tipos habilitada
6969
})
7070
```
7171

72-
## Using with Options API
72+
## Usando a API de Opções
7373

74-
TypeScript should be able to infer most of the types without defining types explicitly. For example, if you have a component with a number `count` property, you will have an error if you try to call a string-specific method on it:
74+
O TypeScript deve ser capaz de inferir a maioria dos tipos sem defini-los explicitamente. Por exemplo, se você tem um componente com uma propriedade numérica `count`, você receberá um erro se tentar chamar um método específico de _string_ nela.
7575

7676
```ts
7777
const Component = defineComponent({
@@ -81,12 +81,12 @@ const Component = defineComponent({
8181
}
8282
},
8383
mounted() {
84-
const result = this.count.split('') // => Property 'split' does not exist on type 'number'
84+
const result = this.count.split('') // => A propriedade 'split' não existe no tipo 'number'
8585
}
8686
})
8787
```
8888

89-
If you have a complex type or interface, you can cast it using [type assertion](https://www.typescriptlang.org/docs/handbook/basic-types.html#type-assertions):
89+
Se você tem um tipo complexo ou uma interface, pode convertê-lo(a) usando a [afirmação de tipo](https://www.typescriptlang.org/docs/handbook/basic-types.html#type-assertions):
9090

9191
```ts
9292
interface Book {
@@ -108,9 +108,9 @@ const Component = defineComponent({
108108
})
109109
```
110110

111-
### Annotating Return Types
111+
### Anotando Tipos de Retorno
112112

113-
Because of the circular nature of Vue’s declaration files, TypeScript may have difficulties inferring the types of computed. For this reason, you may need to annotate the return type of computed properties.
113+
Por causa da natureza circular dos arquivos de declaração do Vue, o TypeScript pode ter dificuldades para inferir os tipos de dados computados. Por esse motivo, você precisa anotar o tipo do retorno de propriedades computadas.
114114

115115
```ts
116116
import { defineComponent } from 'vue'
@@ -122,12 +122,12 @@ const Component = defineComponent({
122122
}
123123
},
124124
computed: {
125-
// needs an annotation
125+
// precisa de uma anotação
126126
greeting(): string {
127127
return this.message + '!'
128128
}
129129

130-
// in a computed with a setter, getter needs to be annotated
130+
// em uma computada com um setter, o getter precisa ser anotado
131131
greetingUppercased: {
132132
get(): string {
133133
return this.greeting.toUpperCase();
@@ -140,9 +140,9 @@ const Component = defineComponent({
140140
})
141141
```
142142

143-
### Annotating Props
143+
### Anotando Propriedades
144144

145-
Vue does a runtime validation on props with a `type` defined. To provide these types to TypeScript, we need to cast the constructor with `PropType`:
145+
O Vue faz uma validação em runtime em propriedades com um `type` definido. Para fornecer esses tipos para o TypeScript, precisamos converter o construtor com `PropType`:
146146

147147
```ts
148148
import { defineComponent, PropType } from 'vue'
@@ -170,11 +170,11 @@ const Component = defineComponent({
170170
})
171171
```
172172

173-
If you find validator not getting type inference or member completion isn’t working, annotating the argument with the expected type may help address these problems.
173+
Se você descobrir que o validador não está obtendo a inferência de tipo ou a conclusão do membro não está funcionando, anotar o argumento com o tipo esperado pode ajudar a resolver esse problema.
174174

175-
## Using with Composition API
175+
## Usando com a API de Composição
176176

177-
On `setup()` function, you don't need to pass a typing to `props` parameter as it will infer types from `props` component option.
177+
Na função `setup()`, você não precisa passar um tipo para o parâmetro `props`, pois os tipos serão inferidos da opção `props` do componente.
178178

179179
```ts
180180
import { defineComponent } from 'vue'
@@ -188,15 +188,15 @@ const Component = defineComponent({
188188
},
189189

190190
setup(props) {
191-
const result = props.message.split('') // correct, 'message' is typed as a string
192-
const filtered = props.message.filter(p => p.value) // an error will be thrown: Property 'filter' does not exist on type 'string'
191+
const result = props.message.split('') // correto, 'message' é tipada como uma string
192+
const filtered = props.message.filter(p => p.value) // um erro será disparado: Propriedade 'filter' não existe no tipo 'string'
193193
}
194194
})
195195
```
196196

197-
### Typing `ref`s
197+
### Tipando `ref`s
198198

199-
Refs infer the type from the initial value:
199+
Refs inferem o tipo do valor inicial:
200200

201201
```ts
202202
import { defineComponent, ref } from 'vue'
@@ -205,26 +205,26 @@ const Component = defineComponent({
205205
setup() {
206206
const year = ref(2020)
207207

208-
const result = year.value.split('') // => Property 'split' does not exist on type 'number'
208+
const result = year.value.split('') // => Propriedade 'split' não existe no tipo 'number'
209209
}
210210
})
211211
```
212212

213-
Sometimes we may need to specify complex types for a ref's inner value. We can do that by simply passing a generic argument when calling ref to override the default inference:
213+
Algumas vezes, podemos precisar especificar tipos complexos para o valor interno de uma ref. Podemos fazer isso simplesmente passando um argumento genérico ao chamar ref para sobrescrever a inferência padrão:
214214

215215
```ts
216-
const year = ref<string | number>('2020') // year's type: Ref<string | number>
216+
const year = ref<string | number>('2020') // tipo do year: Ref<string | number>
217217

218218
year.value = 2020 // ok!
219219
```
220220

221-
::: tip Note
222-
If the type of the generic is unknown, it's recommended to cast `ref` to `Ref<T>`.
221+
::: tip Nota
222+
Se o tipo do genérico é desconhecido, é recomendado converter `ref` para `Ref<T>`.
223223
:::
224224

225-
### Typing `reactive`
225+
### Tipando `reactive`
226226

227-
When typing a `reactive` property, we can use interfaces:
227+
Ao tipar uma propriedade `reactive`, podemos usar interfaces:
228228

229229
```ts
230230
import { defineComponent, reactive } from 'vue'
@@ -238,17 +238,17 @@ export default defineComponent({
238238
name: 'HelloWorld',
239239
setup() {
240240
const book = reactive<Book>({ title: 'Vue 3 Guide' })
241-
// or
241+
// ou
242242
const book: Book = reactive({ title: 'Vue 3 Guide' })
243-
// or
243+
// ou
244244
const book = reactive({ title: 'Vue 3 Guide' }) as Book
245245
}
246246
})
247247
```
248248

249-
### Typing `computed`
249+
### Tipando `computed`
250250

251-
Computed values will automatically infer the type from returned value
251+
Valores computados irão inferir automaticamente o tipo do valor retornado
252252

253253
```ts
254254
import { defineComponent, ref, computed } from 'vue'
@@ -258,10 +258,10 @@ export default defineComponent({
258258
setup() {
259259
let count = ref(0)
260260

261-
// read-only
261+
// apenas leitura
262262
const doubleCount = computed(() => count.value * 2)
263263

264-
const result = doubleCount.value.split('') // => Property 'split' does not exist on type 'number'
264+
const result = doubleCount.value.split('') // => Propriedade 'split' não existe no tipo 'number'
265265
}
266266
})
267267
```

0 commit comments

Comments
 (0)