TypeScript

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

For method decorators in TypeScript, what would you use the propertyKey for?

To call the name of the decorated method

What is the purpose of ambient declaration files in Typescript?

To describe the shape of JavaScript values to the TypeScript compiler

You are a TypeScript developer. You must create an ambient module file to use within a TypeScript module that processes data for the accounting department. What must you include in the .d.ts file to create an ambient module named modOne that contains a function named proc() that accepts a string parameter and returns a string value?

declare module "modOne" { export function proc(s:string) : string; }

When executing --watch, what does the compiler rely on that the node provides?

fs.watch and fs.watchFile

What is the purpose of a TypeScript declaration file?

They allow you to share the types associated with publicly visible signatures of your TypeScript library.

What is one advantage to using TypeScript project references?

They reduce build time by only building changed projects.

What term describes declarations that don't define an implementation?

Ambient

How can you work around writing out declarations before using a module?

Create a shorthand ambient module.

What type of value is number in TypeScript?

Floating point

You must install a package that includes type definition files. You can import and use the external code; however, typings are not available for the imported code in your TypeScript files. What is the most likely explanation?

The package's folder is missing from the typeRoots array defined in the tsconfig.json file.

In TypeScript, what benefit do interfaces offer?

Interfaces signal that an object has certain members available.

Your TypeScript code is bundled into a mylib.js file and you are not using the files property of package.json. How do you declare type definitions for this library for an npm package?

Set the "types" property in your package.json to the path of your mylib.d.ts file.

What is the inheritance result of using the implements keyword to create a new class in Typescript?

The new class receives only the shape (duck typing) of the parent class.

TypeScript is successfully generating JavaScript files on initial builds, but repeat runs result in errors due to duplicate class definitions. Checking your code reveals no duplicated classes. What is the most likely explanation?

TypeScript is including the generated JavaScript code because it is not explicitly excluded in your tsconfig.json file.

Consider the following class Demo: function Foo() {console.log("Foo(): factory evaluated");return function (target: any, propertyKey: number, descriptor: PropertyDescriptor) {console.log("Foo called");};}class Demo {@Foo() method() {}} You receive an error after running the above code. What changes must you make to display Foo called to the logs?

Use string in place of number inside the propertyKey.

There is a TypeScript class called myClass with a decorator of @assemble. What function call does this equate to?

assemble(myClass)

You must create a TypeScript file that executes a function after a timeout. Why is the following code outputting 10 values of 10 instead of 0,1,2,3,4,5,6,7,8,9? for (var i = 0; i < 10; i++) {setTimeout(function() { console.log(i); }, 100 * i);}

i is equal to 10 after the for loop stops executing.

Consider the following tuple elements: let tpls: [number, number, boolean, boolean] = [39, 78, false, true]; While destructuring the above code, which code declaration will capture all four values without throwing any error or using the value undefined?

let [t1, ...t2] = tpls;

What code option successfully declares a variable with an octal number type?

let octal: number = 0o744;


Kaugnay na mga set ng pag-aaral

econ questions to review - basics of the economy

View Set

Chapter 26 Nursing Assessment and Care of Patients with Heart Failure

View Set

Chapter 4: Leveraging Resources and Capabilities

View Set

Chapter 35: Key Pediatric Nursing Interventions

View Set