-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
//! test_output(10) | ||
|
||
import Numbers from "./helpers/Numbers.ts"; | ||
import Num from "./helpers/Num.ts"; | ||
|
||
export default function () { | ||
return Numbers.One + Numbers.Two + Numbers.Three + Numbers.Four; | ||
return Num.One + Num.Two + Num.Three + Num.Four; | ||
} |
4 changes: 2 additions & 2 deletions
4
inputs/passing/helpers/Numbers.ts → inputs/passing/helpers/Num.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
enum Numbers { | ||
enum Num { | ||
Zero, | ||
One, | ||
Two, | ||
Three, | ||
Four, | ||
} | ||
|
||
export default Numbers; | ||
export default Num; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
website/src/playground/files/root/tutorial/typeScriptFeatures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Sometimes TypeScript features generate code. ValueScript supports that too. | ||
|
||
export default function () { | ||
const bigFruit = biggerFruit(Fruit.Lemon, Fruit.Mango); | ||
const point = new Point(3, 4); | ||
|
||
return { | ||
bigFruit: { | ||
raw: bigFruit, | ||
display: Fruit[bigFruit], | ||
note: isCitrus(bigFruit) ? "citrus" : "not citrus", | ||
}, | ||
pointDist: point.dist(), | ||
}; | ||
} | ||
|
||
// Enums don't exist in JavaScript | ||
enum Fruit { | ||
Apple, | ||
Banana, | ||
Orange, | ||
Grape, | ||
Mango, | ||
Pineapple, | ||
Watermelon, | ||
Lemon, | ||
} | ||
|
||
class Point { | ||
constructor( | ||
// By specifying public here, these parameters are automatically initialized | ||
// as fields | ||
public x: number, | ||
public y: number, | ||
) {} | ||
|
||
dist() { | ||
return Math.sqrt(this.x ** 2 + this.y ** 2); | ||
} | ||
} | ||
|
||
function biggerFruit(left: Fruit, right: Fruit): Fruit { | ||
const order = [ | ||
Fruit.Grape, | ||
Fruit.Lemon, | ||
Fruit.Banana, | ||
Fruit.Orange, | ||
Fruit.Apple, | ||
Fruit.Mango, | ||
Fruit.Pineapple, | ||
Fruit.Watermelon, | ||
]; | ||
|
||
return order.indexOf(left) > order.indexOf(right) ? left : right; | ||
} | ||
|
||
function isCitrus(fruit: Fruit): boolean { | ||
switch (fruit) { | ||
case Fruit.Apple: | ||
case Fruit.Banana: | ||
case Fruit.Grape: | ||
case Fruit.Mango: | ||
case Fruit.Pineapple: | ||
case Fruit.Watermelon: | ||
return false; | ||
|
||
case Fruit.Orange: | ||
case Fruit.Lemon: | ||
return true; | ||
} | ||
|
||
// TypeScript knows this is unreachable, so it doesn't complain that we're | ||
// failing to return a boolean. If you comment out one of the cases, it'll | ||
// emit an error. | ||
} |