id stringlengths 16 145 | text stringlengths 1 179k | title stringclasses 1
value |
|---|---|---|
TypeScript/Narrowing_4_0.txt | ## ` instanceof ` narrowing
JavaScript has an operator for checking whether or not a value is an
âinstanceâ of another value. More specifically, in JavaScript ` x
instanceof Foo ` checks whether the _prototype chain_ of ` x ` contains `
Foo.prototype ` . While we wonât dive deep here, and youâll see more of
t... | |
TypeScript/TypeScript_11_0.txt | ## Object
` object ` is a type that represents the non-primitive type, i.e. anything
that is not ` number ` , ` string ` , ` boolean ` , ` bigint ` , ` symbol ` ,
` null ` , or ` undefined ` .
With ` object ` type, APIs like ` Object.create ` can be better represented.
For example:
ts
declare... | |
TypeScript/Top_type_8_0.txt | part5 -------------------
Notes[edit]
^ "Class: BasicObject (Ruby 1.9.2)". Retrieved April 7, 2014.
^ System.Object
^ Python type/class unification
^ Matilla, Hugo (2019-02-27). "Kotlin basics: types. Any, Unit and Nothing". Medium. Retrieved September 16, 2019.
^ "An Overview of the Scala Programming Language" (PD... | |
TypeScript/Decorators_13_0.txt | ### Customize
Site Colours :
System Always Light Always Dark
Code Font :
Cascadia Cascadia (ligatures) Consolas Dank Mono Fira Code JetBrains Mono
OpenDyslexic SF Mono Source Code Pro
| |
TypeScript/Decorators_15_0.txt | ### Using TypeScript
* [ Get Started ](/docs/)
* [ Download ](/download/)
* [ Community ](/community/)
* [ Playground ](/play/)
* [ TSConfig Ref ](/tsconfig/)
* [ Why TypeScript ](/why-create-typescript/)
* [ Design ](/branding/)
* [ Code Samples ](/play/#show-examples)
JavaScript TypeScript
See ho... | |
TypeScript/Top_type_6_0.txt | part3 -------------------
In logic[edit]
The notion of top is also found in propositional calculus, corresponding to a formula which is true in every possible interpretation. It has a similar meaning in predicate calculus. In description logic, top is used to refer to the set of all concepts. This is intuitively like t... | |
TypeScript/TypeScript_7_0.txt | ## Any
In some situations, not all type information is available or its declaration
would take an inappropriate amount of effort. These may occur for values from
code that has been written without TypeScript or a 3rd party library. In these
cases, we might want to opt-out of type checking. To do so, we label these
va... | |
TypeScript/Narrowing_2_0.txt | ## Equality narrowing
TypeScript also uses ` switch ` statements and equality checks like ` === ` ,
` !== ` , ` == ` , and ` != ` to narrow types. For example:
ts
function example(x: string | number, y: string | boolean) {
if (x === y) {
// We can now call any 'string' ... | |
TypeScript/TypeScript_0_0.txt | ## Boolean
The most basic datatype is the simple true/false value, which JavaScript and
TypeScript call a ` boolean ` value.
ts
let isDone: boolean = false;
[Try](https://www.typescriptlang.org/play/#code/DYUwLgBAlgzgIgewHYgFwQEYIaAhkiAXggDNdgYQBuIA)
| |
TypeScript/Narrowing_14_0.txt | #### Functions with JavaScript
1. [ Generic Functions ](/play/?q=436#example/generic-functions "Open the example: Generic Functions")
2. [ Typing Functions ](/play/?q=478#example/typing-functions "Open the example: Typing Functions")
3. [ Function Chaining ](/play/?esModuleInterop=true&q=177#example/fun... | |
TypeScript/Narrowing_18_0.txt | #### Helping with JavaScript
1. [ Quick Fixes ](/play/?q=400#example/quick-fixes "Open the example: Quick Fixes")
2. [ Errors ](/play/?q=242#example/errors "Open the example: Errors")
Explore how TypeScript extends JavaScript to add more safety and tooling.
| |
TypeScript/Narrowing_21_0.txt | #### Meta-Types
1. [ Conditional Types ](/play/?q=134#example/conditional-types "Open the example: Conditional Types")
2. [ Discriminate Types ](/play/?q=131#example/discriminate-types "Open the example: Discriminate Types")
3. [ Indexed Types ](/play/?q=123#example/indexed-types "Open the example: Inde... | |
TypeScript/Narrowing_10_0.txt | ### Customize
Site Colours :
System Always Light Always Dark
Code Font :
Cascadia Cascadia (ligatures) Consolas Dank Mono Fira Code JetBrains Mono
OpenDyslexic SF Mono Source Code Pro
| |
TypeScript/The_Basics_7_0.txt | ## Erased Types
Letâs take a look at what happens when we compile the above function ` greet
` with ` tsc ` to output JavaScript:
ts
"use strict";
function greet(person, date) {
console.log("Hello ".concat(person, ", today is ").concat(date.toDateString(), "!"));
... | |
TypeScript/Top_type_3_0.txt | Object
Smalltalk, JavaScript, Ruby (pre-1.9.2), and some others.
java.lang.Object
Java. Often written without the package prefix, as Object. Also, it is not a supertype of the primitive types; however, since Java 1.5, autoboxing allows implicit or explicit type conversion of a primitive value to Object, e.g., ((Objec... | |
TypeScript/The_Basics_13_0.txt | ### Customize
Site Colours :
System Always Light Always Dark
Code Font :
Cascadia Cascadia (ligatures) Consolas Dank Mono Fira Code JetBrains Mono
OpenDyslexic SF Mono Source Code Pro
| |
TypeScript/The_Basics_25_0.txt | #### Language
1. [ Soundness ](/play/?strictFunctionTypes=false&q=255#example/soundness "Open the example: Soundness")
2. [ Structural Typing ](/play/?q=485#example/structural-typing "Open the example: Structural Typing")
3. [ Type Guards ](/play/?q=191#example/type-guards "Open the example: Type Guards... | |
TypeScript/Top_type_4_0.txt | The following object-oriented languages have no universal base class:
1. C++. The pointer to void type can accept any non-function pointer, even though the void type itself is not the universal type but the unit type. Since C++17, the standard library provides the top type std::any.
2. Objective-C. It is possible to c... | |
TypeScript/The_Basics_26_0.txt | #### Language Extensions
1. [ Enums ](/play/?q=346#example/enums "Open the example: Enums")
2. [ Nominal Typing ](/play/?q=262#example/nominal-typing "Open the example: Nominal Typing")
3. [ Types vs Interfaces ](/play/?q=31#example/types-vs-interfaces "Open the example: Types vs Interfaces")
| |
TypeScript/The_Basics_21_0.txt | #### Helping with JavaScript
1. [ Quick Fixes ](/play/?q=247#example/quick-fixes "Open the example: Quick Fixes")
2. [ Errors ](/play/?q=29#example/errors "Open the example: Errors")
Explore how TypeScript extends JavaScript to add more safety and tooling.
| |
TypeScript/Narrowing_16_0.txt | #### Modern JavaScript
1. [ Async Await ](/play/?q=300#example/async-await "Open the example: Async Await")
2. [ Immutability ](/play/?q=329#example/immutability "Open the example: Immutability")
3. [ Import Export ](/play/?q=324#example/import-export "Open the example: Import Export")
4. [ JSDoc S... | |
TypeScript/Narrowing_9_0.txt | ##### On this page
* typeof type guards
* Truthiness narrowing
* Equality narrowing
* The in operator narrowing
* instanceof narrowing
* Assignments
* Control flow analysis
* Using type predicates
* Assertion functions
* Discriminated unions
* The never type
* Exhaustiveness... | |
TypeScript/TypeScript_1_0.txt | ## Number
As in JavaScript, all numbers in TypeScript are either floating point values
or BigIntegers. These floating point numbers get the type ` number ` , while
BigIntegers get the type ` bigint ` . In addition to hexadecimal and decimal
literals, TypeScript also supports binary and octal literals introduced in
EC... | |
TypeScript/The_Basics_15_0.txt | ### Using TypeScript
* [ Get Started ](/docs/)
* [ Download ](/download/)
* [ Community ](/community/)
* [ Playground ](/play/)
* [ TSConfig Ref ](/tsconfig/)
* [ Why TypeScript ](/why-create-typescript/)
* [ Design ](/branding/)
* [ Code Samples ](/play/#show-examples)
JavaScript TypeScript
See ho... | |
TypeScript/Decorators_4_0.txt | ## Decorator Composition
Multiple decorators can be applied to a declaration, for example on a single
line:
ts
@f @g x
[Try](https://www.typescriptlang.org/play/#code/PTAEAEFMA8AdIE4EsC2kB2AXAhgGwCKQDGA9gtpmQM4BQIE6JAoggtTQGYCu6RmSJdKA4AKAJSgA3gF9OPPgKEBzcVNn0AtFqJdMWjTXAcIS0NCA)
On ... | |
TypeScript/TypeScript_9_0.txt | ## Null and Undefined
In TypeScript, both ` undefined ` and ` null ` actually have their types named
` undefined ` and ` null ` respectively. Much like ` void ` , theyâre not
extremely useful on their own:
ts
// Not much else we can assign to these variables!
let u: undefined = unde... | |
TypeScript/Decorators_14_1.txt | i04StwM9k9Vjos9RnbD+AU9IjMDF/g6ENwucBvFuAPyfHNNdDGv9HXPkNqFI3ch0ht1ojhbni5a2uw3gzoIxWsem+TWTLjvT6Xt+oCDyu5e3mFF3k34dSQzouyZRg7Lxu3xaHck05/vDb4YZMdwVVdHMr/aTZhw/93AKUF9oPv0YNPO3hnrLg+c0uu6J/nrrAfjYu7HomtMuYsS2i70bsIkXCu1rrRpGA2WSgcA7dI7wa0BHfqljw8g0SN0ecYq3DtE3/Y1Uj84ch4HmdakO4/5ku3jBEY7L/XlG8G5Eh8fKNwHDwxehBE0ekPiQuLzA... | |
TypeScript/The_Basics_17_0.txt | #### Functions with JavaScript
1. [ Generic Functions ](/play/?q=436#example/generic-functions "Open the example: Generic Functions")
2. [ Typing Functions ](/play/?q=217#example/typing-functions "Open the example: Typing Functions")
3. [ Function Chaining ](/play/?esModuleInterop=true&q=138#example/fun... | |
TypeScript/Top_type_2_0.txt | part2 -------------------
Support in programming languages[edit]
Several typed programming languages provide explicit support for the top type.
In statically-typed languages, there are two different, often confused, concepts when discussing the top type.
A universal base class or other item at the top of a run time cla... | |
TypeScript/The_Basics_23_0.txt | #### Type Primitives
1. [ Tuples ](/play/?q=381#example/tuples "Open the example: Tuples")
2. [ Built-in Utility Types ](/play/?strictNullChecks=true&q=313#example/built-in-utility-types "Open the example: Built-in Utility Types")
3. [ Nullable Types ](/play/?strictNullChecks=false&q=416#example/nullabl... | |
TypeScript/The_Basics_24_0.txt | #### Meta-Types
1. [ Conditional Types ](/play/?q=68#example/conditional-types "Open the example: Conditional Types")
2. [ Discriminate Types ](/play/?q=286#example/discriminate-types "Open the example: Discriminate Types")
3. [ Indexed Types ](/play/?q=25#example/indexed-types "Open the example: Indexe... | |
TypeScript/Decorators_18_0.txt | #### Working With Classes
1. [ Classes 101 ](/play/?q=298#example/classes-101 "Open the example: Classes 101")
2. [ This ](/play/?q=272#example/this "Open the example: This")
3. [ Generic Classes ](/play/?q=276#example/generic-classes "Open the example: Generic Classes")
4. [ Mixins ](/play/?q=390#... | |
TypeScript/The_Basics_20_0.txt | #### External APIs
1. [ TypeScript with Web ](/play/?useJavaScript=trueq=104#example/typescript-with-web "Open the example: TypeScript with Web")
2. [ TypeScript with React ](/play/?jsx=2&esModuleInterop=true&q=89#example/typescript-with-react "Open the example: TypeScript with React")
3. [ TypeScript w... | |
TypeScript/Narrowing_24_0.txt | ### Community
* [ Get Help ](/community)
* [ Blog ](https://devblogs.microsoft.com/typescript/)
* [ GitHub Repo ](https://github.com/microsoft/TypeScript/#readme)
* [ Community Chat ](https://discord.gg/typescript)
* [ @TypeScript ](https://twitter.com/TypeScript)
* [ Mastodon ](https://fosstodon.org/@Typ... | |
TypeScript/Narrowing_1_1.txt | true, value: true
[Try](https://www.typescriptlang.org/play/#code/PTAECMHsBcAtUgM1HApgZ1aAThgrgDbSgCWAdqAOTTZ6qUBQAQpJAagIZkAUARLKgIFIvAJQBuUCBQBPAA6oAXBFbsuAGlAA3DgTrKadBgEJjvAO6RsBACa9J06PKUpaqTaE869Lw6iA)
Itâs fairly popular to leverage this behavior, especially for guarding
against values like ` null... | |
TypeScript/Decorators_7_0.txt | ## Method Decorators
A _Method Decorator_ is declared just before a method declaration. The
decorator is applied to the _Property Descriptor_ for the method, and can be
used to observe, modify, or replace a method definition. A method decorator
cannot be used in a declaration file, on an overload, or in any other amb... | |
TypeScript/The_Basics_19_0.txt | #### Modern JavaScript
1. [ Async Await ](/play/?q=285#example/async-await "Open the example: Async Await")
2. [ Immutability ](/play/?q=269#example/immutability "Open the example: Immutability")
3. [ Import Export ](/play/?q=506#example/import-export "Open the example: Import Export")
4. [ JSDoc S... | |
TypeScript/Decorators_9_0.txt | ## Property Decorators
A _Property Decorator_ is declared just before a property declaration. A
property decorator cannot be used in a declaration file, or in any other
ambient context (such as in a ` declare ` class).
The expression for the property decorator will be called as a function at
runtime, with the follow... | |
TypeScript/Narrowing_7_0.txt | ## Using type predicates
Weâve worked with existing JavaScript constructs to handle narrowing so far,
however sometimes you want more direct control over how types change
throughout your code.
To define a user-defined type guard, we simply need to define a function whose
return type is a _type predicate_ :
... | |
TypeScript/Narrowing_1_0.txt | ## ` typeof ` type guards
As weâve seen, JavaScript supports a ` typeof ` operator which can give very
basic information about the type of values we have at runtime. TypeScript
expects this to return a certain set of strings:
* ` "string" `
* ` "number" `
* ` "bigint" `
* ` "boolean" `
* ` "symbol" `
*... | |
TypeScript/Decorators_14_0.txt | ### Popular Documentation Pages
* [ Everyday Types ](/docs/handbook/2/everyday-types.html)
All of the common types in TypeScript
* [ Creating Types from Types ](/docs/handbook/2/types-from-types.html)
Techniques to make more elegant types
* [ More on Functions ](/docs/handbook/2/functions.html)
How to prov... | |
TypeScript/Top_type_7_0.txt | part4 -------------------
See also[edit]
Singly rooted hierarchy
| |
TypeScript/Narrowing_6_0.txt | ## Control flow analysis
Up until this point, weâve gone through some basic examples of how
TypeScript narrows within specific branches. But thereâs a bit more going on
than just walking up from every variable and looking for type guards in ` if `
s, ` while ` s, conditionals, etc. For example
ts
... | |
TypeScript/Narrowing_22_0.txt | #### Language
1. [ Soundness ](/play/?strictFunctionTypes=false&q=160#example/soundness "Open the example: Soundness")
2. [ Structural Typing ](/play/?q=90#example/structural-typing "Open the example: Structural Typing")
3. [ Type Guards ](/play/?q=62#example/type-guards "Open the example: Type Guards")... | |
TypeScript/Decorators_17_0.txt | #### Functions with JavaScript
1. [ Generic Functions ](/play/?q=49#example/generic-functions "Open the example: Generic Functions")
2. [ Typing Functions ](/play/?q=212#example/typing-functions "Open the example: Typing Functions")
3. [ Function Chaining ](/play/?esModuleInterop=true&q=374#example/func... | |
TypeScript/Decorators_23_0.txt | #### Type Primitives
1. [ Tuples ](/play/?q=287#example/tuples "Open the example: Tuples")
2. [ Built-in Utility Types ](/play/?strictNullChecks=true&q=195#example/built-in-utility-types "Open the example: Built-in Utility Types")
3. [ Nullable Types ](/play/?strictNullChecks=false&q=94#example/nullable... | |
TypeScript/The_Basics_8_0.txt | ## Downleveling
One other difference from the above was that our template string was rewritten
from
js
`Hello ${person}, today is ${date.toDateString()}!`;
to
js
"Hello ".concat(person, ", today is ").concat(date.toDateString(), "!");
Why did this happen?
Template st... | |
TypeScript/Decorators_20_0.txt | #### External APIs
1. [ TypeScript with Web ](/play/?useJavaScript=trueq=446#example/typescript-with-web "Open the example: TypeScript with Web")
2. [ TypeScript with React ](/play/?jsx=2&esModuleInterop=true&q=237#example/typescript-with-react "Open the example: TypeScript with React")
3. [ TypeScript ... | |
TypeScript/Decorators_24_0.txt | #### Meta-Types
1. [ Conditional Types ](/play/?q=382#example/conditional-types "Open the example: Conditional Types")
2. [ Discriminate Types ](/play/?q=257#example/discriminate-types "Open the example: Discriminate Types")
3. [ Indexed Types ](/play/?q=25#example/indexed-types "Open the example: Index... | |
TypeScript/Narrowing_23_0.txt | #### Language Extensions
1. [ Enums ](/play/?q=5#example/enums "Open the example: Enums")
2. [ Nominal Typing ](/play/?q=80#example/nominal-typing "Open the example: Nominal Typing")
3. [ Types vs Interfaces ](/play/?q=64#example/types-vs-interfaces "Open the example: Types vs Interfaces")
| |
TypeScript/Decorators_3_0.txt | ## Decorator Factories
If we want to customize how a decorator is applied to a declaration, we can
write a decorator factory. A _Decorator Factory_ is simply a function that
returns the expression that will be called by the decorator at runtime.
We can write a decorator factory in the following fashion:
... | |
TypeScript/Narrowing_8_2.txt | iminated
union_ , and can narrow out the members of the union.
In this case, ` kind ` was that common property (which is whatâs considered
a _discriminant_ property of ` Shape ` ). Checking whether the ` kind `
property was ` "circle" ` got rid of every type in ` Shape ` that didnât
have a ` kind ` property with t... | |
TypeScript/The_Basics_6_0.txt | ## Explicit Types
Up until now, we havenât told TypeScript what ` person ` or ` date ` are.
Letâs edit the code to tell TypeScript that ` person ` is a ` string ` , and
that ` date ` should be a ` Date ` object. Weâll also use the `
toDateString() ` method on ` date ` .
ts
function greet... | |
TypeScript/The_Basics_0_0.txt | # The Basics
Welcome to the first page of the handbook. If this is your first experience
with TypeScript - you may want to start at one of the ' [ Getting Started
](https://www.typescriptlang.org/docs/handbook/intro.html#get-started) '
guides
Each and every value in JavaScript has a set of behaviors you can observe ... | |
TypeScript/Narrowing_17_0.txt | #### External APIs
1. [ TypeScript with Web ](/play/?useJavaScript=trueq=291#example/typescript-with-web "Open the example: TypeScript with Web")
2. [ TypeScript with React ](/play/?jsx=2&esModuleInterop=true&q=252#example/typescript-with-react "Open the example: TypeScript with React")
3. [ TypeScript ... | |
TypeScript/TypeScript_5_0.txt | ## Enum
A helpful addition to the standard set of datatypes from JavaScript is the `
enum ` . As in languages like C#, an enum is a way of giving more friendly
names to sets of numeric values.
ts
enum Color {
Red,
Green,
Blue,
}
let c: Color =... | |
TypeScript/The_Basics_11_0.txt | ## ` strictNullChecks `
By default, values like ` null ` and ` undefined ` are assignable to any other
type. This can make writing some code easier, but forgetting to handle ` null
` and ` undefined ` is the cause of countless bugs in the world - some
consider it a [ billion dollar mistake
](https://www.youtube.com/w... | |
TypeScript/The_Basics_14_1.txt | i04StwM9k9Vjos9RnbD+AU9IjMDF/g6ENwucBvFuAPyfHNNdDGv9HXPkNqFI3ch0ht1ojhbni5a2uw3gzoIxWsem+TWTLjvT6Xt+oCDyu5e3mFF3k34dSQzouyZRg7Lxu3xaHck05/vDb4YZMdwVVdHMr/aTZhw/93AKUF9oPv0YNPO3hnrLg+c0uu6J/nrrAfjYu7HomtMuYsS2i70bsIkXCu1rrRpGA2WSgcA7dI7wa0BHfqljw8g0SN0ecYq3DtE3/Y1Uj84ch4HmdakO4/5ku3jBEY7L/XlG8G5Eh8fKNwHDwxehBE0ekPiQuLzA... | |
TypeScript/The_Basics_16_0.txt | #### JavaScript Essentials
1. [ Hello World ](/play/?target=1&q=130#example/hello-world "Open the example: Hello World")
2. [ Objects and Arrays ](/play/?strict=false&q=58#example/objects-and-arrays "Open the example: Objects and Arrays")
3. [ Functions ](/play/?noImplicitAny=false&q=191#example/functio... | |
TypeScript/The_Basics_2_0.txt | ## Non-exception Failures
So far weâve been discussing certain things like runtime errors - cases
where the JavaScript runtime tells us that it thinks something is nonsensical.
Those cases come up because [ the ECMAScript specification
](https://tc39.github.io/ecma262/) has explicit instructions on how the
language... | |
TypeScript/TypeScript_8_0.txt | ## Void
` void ` is a little like the opposite of ` any ` : the absence of having any
type at all. You may commonly see this as the return type of functions that do
not return a value:
ts
function warnUser(): void {
console.log("This is my warning message");
}
[Try... | |
TypeScript/Narrowing_8_3.txt | ape ` union, will cause a TypeScript error:
ts
interface Triangle {
kind: "triangle";
sideLength: number;
}
type Shape = Circle | Square | Triangle;
function getArea(shape: Shape) {
switch (shape.kind) {
... | |
TypeScript/Decorators_19_0.txt | #### Modern JavaScript
1. [ Async Await ](/play/?q=423#example/async-await "Open the example: Async Await")
2. [ Immutability ](/play/?q=314#example/immutability "Open the example: Immutability")
3. [ Import Export ](/play/?q=88#example/import-export "Open the example: Import Export")
4. [ JSDoc Su... | |
TypeScript/The_Basics_5_0.txt | ## Emitting with Errors
One thing you might not have noticed from the last example was that our `
hello.js ` file changed again. If we open that file up then weâll see that
the contents still basically look the same as our input file. That might be a
bit surprising given the fact that ` tsc ` reported an error abou... | |
TypeScript/Narrowing_8_1.txt | }
}
[Try](https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgMoAs4AcUG8BQyyA1qACYBcyARAsFAgDYTXIA+NAzgI4CucUFgG5CyKHDLBenAPxUQvALYAjaCKKdgZCABkIIAOZh0c5ApVr8AX3z4A9HeQBaFwl5gXT-DF4gEYYAB7EGQDCDAAQUE4AApOTBwqDGwIAEpkAiJgGGQ4hIgAOlIQMmQAXgqaOgZmanTMojFw3igQgFk4YwKABQBJZAAqZHiUgvFJaQBCQaGA... | |
TypeScript/Decorators_12_0.txt | ##### On this page
* Introduction
* Decorators
* Decorator Factories
* Decorator Composition
* Decorator Evaluation
* Class Decorators
* Method Decorators
* Accessor Decorators
* Property Decorators
* Parameter Decorators
* Metadata
[ Previous Nightly Builds How to use a nightly bu... | |
TypeScript/Narrowing_0_1.txt | SyEFCpce5AJRjuvRAG8AUIkHBE+KAE9k2OGqIlyiALynEAIhoNm5yQuUrETbFBBMk5iwDpnO1AQNeOwBqQTBhKABuBxUAeljHRKTEgD0AfgcAXwdnV3cUDEMyRFChEWi4hNSMzKA)
There are a couple of different constructs TypeScript understands for
narrowing.
| |
TypeScript/TypeScript_4_0.txt | ## Tuple
Tuple types allow you to express an array with a fixed number of elements
whose types are known, but need not be the same. For example, you may want to
represent a value as a pair of a ` string ` and a ` number ` :
ts
// Declare a tuple type
let x: [string, number];
... | |
TypeScript/TypeScript_6_0.txt | ## Unknown
We may need to describe the type of variables that we do not know when we are
writing an application. These values may come from dynamic content â e.g.
from the user â or we may want to intentionally accept all values in our
API. In these cases, we want to provide a type that tells the compiler and
fut... | |
TypeScript/Narrowing_11_0.txt | ### Popular Documentation Pages
* [ Everyday Types ](/docs/handbook/2/everyday-types.html)
All of the common types in TypeScript
* [ Creating Types from Types ](/docs/handbook/2/types-from-types.html)
Techniques to make more elegant types
* [ More on Functions ](/docs/handbook/2/functions.html)
How to prov... | |
TypeScript/Decorators_26_0.txt | #### Language Extensions
1. [ Enums ](/play/?q=351#example/enums "Open the example: Enums")
2. [ Nominal Typing ](/play/?q=20#example/nominal-typing "Open the example: Nominal Typing")
3. [ Types vs Interfaces ](/play/?q=14#example/types-vs-interfaces "Open the example: Types vs Interfaces")
| |
TypeScript/Narrowing_20_0.txt | #### Type Primitives
1. [ Tuples ](/play/?q=12#example/tuples "Open the example: Tuples")
2. [ Built-in Utility Types ](/play/?strictNullChecks=true&q=107#example/built-in-utility-types "Open the example: Built-in Utility Types")
3. [ Nullable Types ](/play/?strictNullChecks=false&q=74#example/nullable-... | |
TypeScript/Decorators_8_0.txt | ## Accessor Decorators
An _Accessor Decorator_ is declared just before an accessor declaration. The
accessor decorator is applied to the _Property Descriptor_ for the accessor
and can be used to observe, modify, or replace an accessorâs definitions. An
accessor decorator cannot be used in a declaration file, or in ... | |
TypeScript/The_Basics_3_0.txt | ## Types for Tooling
TypeScript can catch bugs when we make mistakes in our code. Thatâs great,
but TypeScript can _also_ prevent us from making those mistakes in the first
place.
The type-checker has information to check things like whether weâre
accessing the right properties on variables and other properties.... | |
TypeScript/TypeScript_2_0.txt | ## String
Another fundamental part of creating programs in JavaScript for webpages and
servers alike is working with textual data. As in other languages, we use the
type ` string ` to refer to these textual datatypes. Just like JavaScript,
TypeScript also uses double quotes ( ` " ` ) or single quotes ( ` ' ` ) to
sur... | |
TypeScript/Decorators_0_0.txt | # Decorators
> NOTEÂ This document refers to an experimental stage 2 decorators
> implementation. Stage 3 decorator support is available since Typescript 5.0.
> See: [ Decorators in Typescript 5.0
> ](https://devblogs.microsoft.com/typescript/announcing-
> typescript-5-0/#decorators)
| |
TypeScript/Decorators_22_0.txt | #### Primitives
1. [ Any ](/play/?q=42#example/any "Open the example: Any")
2. [ Literals ](/play/?q=438#example/literals "Open the example: Literals")
3. [ Union and Intersection Types ](/play/?q=446#example/union-and-intersection-types "Open the example: Union and Intersection Types")
4. [ Unknow... | |
TypeScript/The_Basics_18_0.txt | #### Working With Classes
1. [ Classes 101 ](/play/?q=99#example/classes-101 "Open the example: Classes 101")
2. [ This ](/play/?q=51#example/this "Open the example: This")
3. [ Generic Classes ](/play/?q=208#example/generic-classes "Open the example: Generic Classes")
4. [ Mixins ](/play/?q=278#ex... | |
TypeScript/Decorators_10_0.txt | ## Parameter Decorators
A _Parameter Decorator_ is declared just before a parameter declaration. The
parameter decorator is applied to the function for a class constructor or
method declaration. A parameter decorator cannot be used in a declaration
file, an overload, or in any other ambient context (such as in a ` de... | |
TypeScript/Narrowing_0_0.txt | # Narrowing
Imagine we have a function called ` padLeft ` .
ts
function padLeft(padding: number | string, input: string): string {
throw new Error("Not implemented yet!");
}
[Try](https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABABwIYBMAyBTYUAUa66MYA5gFyJg... | |
TypeScript/Decorators_27_0.txt | ### Community
* [ Get Help ](/community)
* [ Blog ](https://devblogs.microsoft.com/typescript/)
* [ GitHub Repo ](https://github.com/microsoft/TypeScript/#readme)
* [ Community Chat ](https://discord.gg/typescript)
* [ @TypeScript ](https://twitter.com/TypeScript)
* [ Mastodon ](https://fosstodon.org/@Typ... | |
TypeScript/Top_type_5_0.txt | Other languages[edit]
Languages that are not object-oriented usually have no universal supertype, or subtype polymorphism support.
While Haskell purposefully lacks subtyping, it has several other forms of polymorphism including parametric polymorphism. The most generic type class parameter is an unconstrained parameter... | |
TypeScript/Decorators_10_1.txt | zYfzheLt3CkVjcU8iZpyZ4XJFewORxOoHGkwQ11u93pmGePHenyB7L+3ICvMs-NA4J4FuhNvF1IWCyQ0lAs87-u7EqoLe32+kZH3KdJ4vJCCGI2goBIe-+ouP99Ps1b59Au-3W8jkfGBQDjBxpQmDBMFxORGkwQkWlaSC0CwKgLiAiUQOgG47Dw0AIiZFleDPP9zwQso3j7SAqIAUQQMoEG8ThViodYmnfAITTSKCsEeYIkTI0AVTIkTtzEhYpEwAwEDiNMM0ebBYFgXBrGSQlVmKFDoNPQSlQ0JUgA)
The ` @required ` deco... | |
TypeScript/The_Basics_1_0.txt | ## Static type-checking
Think back to that ` TypeError ` we got earlier from trying to call a ` string
` as a function. _Most people_ donât like to get any sorts of errors when
running their code - those are considered bugs! And when we write new code, we
try our best to avoid introducing new bugs.
If we add just ... | |
TypeScript/Decorators_25_0.txt | #### Language
1. [ Soundness ](/play/?strictFunctionTypes=false&q=439#example/soundness "Open the example: Soundness")
2. [ Structural Typing ](/play/?q=373#example/structural-typing "Open the example: Structural Typing")
3. [ Type Guards ](/play/?q=315#example/type-guards "Open the example: Type Guards... | |
TypeScript/Narrowing_13_0.txt | #### JavaScript Essentials
1. [ Hello World ](/play/?target=1&q=249#example/hello-world "Open the example: Hello World")
2. [ Objects and Arrays ](/play/?strict=false&q=330#example/objects-and-arrays "Open the example: Objects and Arrays")
3. [ Functions ](/play/?noImplicitAny=false&q=229#example/functi... | |
TypeScript/Narrowing_12_0.txt | ### Using TypeScript
* [ Get Started ](/docs/)
* [ Download ](/download/)
* [ Community ](/community/)
* [ Playground ](/play/)
* [ TSConfig Ref ](/tsconfig/)
* [ Why TypeScript ](/why-create-typescript/)
* [ Design ](/branding/)
* [ Code Samples ](/play/#show-examples)
JavaScript TypeScript
See ho... | |
TypeScript/Decorators_1_0.txt | ## Introduction
With the introduction of Classes in TypeScript and ES6, there now exist
certain scenarios that require additional features to support annotating or
modifying classes and class members. Decorators provide a way to add both
annotations and a meta-programming syntax for class declarations and members.
>... | |
TypeScript/The_Basics_14_0.txt | ### Popular Documentation Pages
* [ Everyday Types ](/docs/handbook/2/everyday-types.html)
All of the common types in TypeScript
* [ Creating Types from Types ](/docs/handbook/2/types-from-types.html)
Techniques to make more elegant types
* [ More on Functions ](/docs/handbook/2/functions.html)
How to prov... | |
TypeScript/Narrowing_15_0.txt | #### Working With Classes
1. [ Classes 101 ](/play/?q=146#example/classes-101 "Open the example: Classes 101")
2. [ This ](/play/?q=351#example/this "Open the example: This")
3. [ Generic Classes ](/play/?q=487#example/generic-classes "Open the example: Generic Classes")
4. [ Mixins ](/play/?q=336#... | |
TypeScript/Decorators_11_1.txt | e `
@Reflect.metadata ` decorator. You could consider it the equivalent of the
following TypeScript:
ts
class Line {
private _start: Point;
private _end: Point;
@validate
@Reflect.metadata("design:type", Point)
set start(value: Point) {
... | |
TypeScript/The_Basics_10_0.txt | ## ` noImplicitAny `
Recall that in some places, TypeScript doesnât try to infer types for us and
instead falls back to the most lenient type: ` any ` . This isnât the worst
thing that can happen - after all, falling back to ` any ` is just the plain
JavaScript experience anyway.
However, using ` any ` often def... | |
TypeScript/Decorators_21_0.txt | #### Helping with JavaScript
1. [ Quick Fixes ](/play/?q=382#example/quick-fixes "Open the example: Quick Fixes")
2. [ Errors ](/play/?q=448#example/errors "Open the example: Errors")
Explore how TypeScript extends JavaScript to add more safety and tooling.
| |
TypeScript/Decorators_2_0.txt | ## Decorators
A _Decorator_ is a special kind of declaration that can be attached to a
class declaration , method , accessor , property , or parameter .
Decorators use the form ` @expression ` , where ` expression ` must evaluate
to a function that will be called at runtime with information about the
decorat... | |
TypeScript/Decorators_11_0.txt | ## Metadata
Some examples use the ` reflect-metadata ` library which adds a polyfill for
an [ experimental metadata API
](https://github.com/rbuckton/ReflectDecorators) . This library is not yet
part of the ECMAScript (JavaScript) standard. However, once decorators are
officially adopted as part of the ECMAScript sta... | |
TypeScript/TypeScript_10_0.txt | ## Never
The ` never ` type represents the type of values that never occur. For
instance, ` never ` is the return type for a function expression or an arrow
function expression that always throws an exception or one that never returns.
Variables also acquire the type ` never ` when narrowed by any type guards
that ca... | |
TypeScript/TypeScript_12_0.txt | ## Type assertions
Sometimes youâll end up in a situation where youâll know more about a
value than TypeScript does. Usually, this will happen when you know the type
of some entity could be more specific than its current type.
_Type assertions_ are a way to tell the compiler âtrust me, I know what
Iâm doing.... | |
R_base_all/R_base_all_234_0.txt | [ RDocumentation ](/)
Moon [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)
Search all packages and functions
[ base (version 3.6.2 ) ](/packages/base/versions/3.6.2)
# transform: Transform an Object, for Example a Data Frame
## Description
` transform ` is a... | |
R_base_all/weighted-average-excel4_295_0.txt | 63. Claudia says:
September 8, 2014 at 9:34 am | |
R_base_all/pandas.Series.str.split.html8_46_0.txt |
>>> import re
>>> s.str.split(re.compile(r"\.jpg"), expand=True)
0 1
0 foojpgbar
When ` regex=False ` , pat is interpreted as the string itself |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.