[TypeScript ] What Happens to Compiled Interfaces

This lesson covers using your first TypeScript Interface and what happens to the Interface when it is compiled down to JavaScript.

Define the interfaces:

// interfaces.ts

export interface Person {
    name: String
}

export interface SocialNetwork{
    title: String;
    getPeople(): Person[];
}

Use interface:

import {SocialNetwork} from ‘./interfaces‘;

class SocialNetworks implements SocialNetwork{
    title = "Facebook";

    getPeople(){
        return [{name: ‘John‘}]
    }
}

new SocialNetworks();

To notice that, interfaces won‘t output to the js file, it is just used when compile time.

时间: 2024-10-07 19:05:46

[TypeScript ] What Happens to Compiled Interfaces的相关文章

TypeScript: type alias 与 interface

官方文档中有关于两者对比的信息,隐藏在 TypeScript Handbook 中,见 Interfaces vs. Type Aliases 部分. 但因为这一部分很久没更新了,所以其中描述的内容不一定全对. 比如, 区别点之一:Type Alias 不会创建新的类型,体现在错误信息上. One difference is, that interfaces create a new name that is used everywhere. Type aliases don't create

[TypeScript] Typescript Interfaces vs Aliases Union & Intersection Types

TypeScript has 'interface' and 'type', so when to use which? interface hasName { firstName: string; lastName: string; } interface hasAddress { address: string } type Player = (hasName & hasAddress) | null; let player: Player = {firstName: 'Joe', last

[TypeScript] Using Interfaces to Describe Types in TypeScript

It’s easy to pass the wrong value to a function. Typescript interfaces are great because they catch errors at compile time or in an IDE. In this lesson we’ll learn how to describe a type shape with Typescript interfaces. Using interface to describe a

VSCode typescript ctrl+shift+b can't be compiled error:TS5007

环境: vscode:1.12.2 node 7.4.0 TypeScript:2.3.2 从svn 更新下来,别的电脑环境编译是没问题的,在我的电脑上编译失败并出现以下错误 error TS5007: Cannot resolve referenced file: '.'. error TS5023: Unknown option 'p' Use the '--help' flag to see options. 错误的原因是typescript 版本的问题. 解决方法是: 我的电脑右键属性→

TypeScript - Interfaces

简介 关注于数据值的 ‘shape’的类型检查是TypeScript核心设计原则.这种模式有时被称为‘鸭子类型’或者‘结构子类型化’. . 在TypeScript中接口interfaces的责任就是命名这些类型,而且还是你的代码之间或者是与外部项目代码的契约. 初见Interface 理解interface的最好办法,就是写个hello world程序: function printLabel(labelledObj: {label: string}) { console.log(labelle

[TypeScript] Loading Compiled TypeScript Files in Browser with SystemJS

TypeScript outputs JavaScript, but what are you supposed to do with it? This lesson shows how to take the output and use SystemJS as the module loader so that you can use the files in your browser. To use system.js, first create a index.html, add sys

Getting started with TypeScript and Sublime Text -- 摘自https://cmatskas.com/getting-started-with-typescript-and-sublime-text/

Getting started with TypeScript and Sublime Text 04 March 2015  18 Comments  Posted in JavaScript, Open Source, TypeScript, Sublime Text UPDATED: This post has been rewritten around the official TypeScript plugin Typescript is awesome, period. TypeSc

Angular 2: Why TypeScript?

https://vsavkin.com/writing-angular-2-in-typescript-1fa77c78d8e8 Angular 2 is written in TypeScript. In this article I will talk about why we made the decision. I'll also share my experience of working with TypeScript: how it affects the way I write

TypeScript手册翻译系列8-常见错误与Mixins

常见错误 下面列出了在使用TypeScript语言和编译器期间,经常会遇到的一些常见错误. "tsc.exe" exited with error code 1. 解决方案: 检查文件编码为UTF-8 - https://typescript.codeplex.com/workitem/1587 external module XYZ cannot be resolved 解决方案:检查模块路径是大小写敏感- https://typescript.codeplex.com/workit