Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

717
Visualizações
How to use types/select2 in a Angular 2 project?

I am developing Angular 2 project with Typescript. I want to be able to use select2 and I don't see any stable feature rich plugins equivalent to select2. However I came across types/select2 in DefinitelyTyped project. I'm not sure how to use them in my project. I can't find examples of other DefinitelyTyped libraries also. I'm new to both TS and Angular 2. Can someone provide pointers on how I should used this ?

I understand I can include the library using my package.json but no idea how I can use in a component.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

With @types/select2 installed, it allows the typescript compiler to do static type checking to ensure the Select2 library is being called correctly. It does not change the way you use the select2 - you still need to install the Select2 library and use it as you would have without type checking.

For external dependencies (like jQuery or Select2) you should install their corresponding type definition files, so that the typescript compiler can resolve the external types at compile-time. This is preferred over declaring an any types (i.e. declare var $: any)

Make sure you install jQuery types as well :

npm install @types/jquery

This will install the type definitions under node_modules/@types/jQuery. By default, the typescript compiler will resolve types from the node_modules/@types folder.

For TypeScript NodeJS packages, you can generate type definition files as part of the compilation step and specify index.d.ts in the typings property of your package.json file. In this case, you don't necessarily need to export the type definitions to node_modules/@types.

about 4 years ago · Santiago Trujillo Relatório

0

I had a similar issue and fixed it by importing:

import 'select2';

which I had installed earlier:

npm install select2 --save

Once you've done that, you can use the library through jquery as usual.

about 4 years ago · Santiago Trujillo Relatório

0

I solve this by

import { Select2} from 'select2'

and also install:

npm install @types/select2@4.0.48

Now i have to run test but no more errors on Typescript slint

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda