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

307
Visualizações
Which of the listed import statements are identical?

I have identified the following import statements in node. Do all the statements below import mathgraph with a different namespace scope, or which import styles are identical?

const/var/let mathgraph = require('mathgraph');

import * as mathgraph from 'mathgraph';
import mathgraph from 'mathgraph';
import { mathgraph } from 'mathgraph';
import mathgraph = require('mathgraph');
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

// mathgrab lib
export default { foo: 'foo' }

// your code
import mathgraph from 'mathgraph';
mathgrab.foo

This imports the default export.


// mathgrab lib
export const someObject = { foo: 'foo' }

// your code
import { someObject } from 'mathgraph';
someObject.foo

This imports a named export.


// mathgrab lib
export const someObject = { foo: 'foo' }
export default { bar: 'bar' }

// your code
import mathgraph, { someObject } from 'mathgraph';
mathgrab.someObject.foo
mathgrab.default.bar

You can even combine these two to import both kinds of exports in one line.


// mathgrab lib
export const someObject = { foo: 'foo' }
export default { bar: 'bar' }

// your code
import * as mathgraph from 'mathgraph';
mathgrab.someObject.foo
mathgrab.default.bar

This imports all exports as a single object. The default export will be on the default property of this object.


const mathgraph = require('mathgraph');

This only works in node, and is functionally the same as import *, but it's a dynamic runtime require, rather than than a compile time import. That means that typescript can't use the types of the imported file. require is just a function, so it returns a value of type any, thereby missing out on all typing info.

Don't use require with typescript, you pretty always want to use import instead.


import mathgraph = require('mathgraph');

And lastly, this is invalid syntax. So don't do that.

about 4 years ago · Juan Pablo Isaza 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