declare

Is there ever a reason to use the declare keyword in front of types and interfaces?

送分小仙女□ 提交于 2021-01-27 02:53:27
问题 I have come across some code like this: declare type A = { ... }; declare interface B { ... } From searching for the declare keyword (and none of the hits pointed to me the TypeScript docs for some reason), declare is used when a variable exists in JavaScript and you need to reference it from TypeScript, so you declare to the compiler that this variable indeed exists. All examples I have found that use this keyword use it like this: declare var a; Why would I ever use it in front of a type or

TypeScript define object structure for later use

荒凉一梦 提交于 2020-08-02 06:06:40
问题 Is it possible to define an object structure in TypeScript that can be used then as parameter type? What I mean: I have (let's say) 5 functions that return the same object structure like so: foo(): { bar: string, baz: boolean, idk: number } { ... } bar(): { bar: string, baz: boolean, idk: number } { ... } ... the problem with this is that I have to define this structure at every function that returns an object like this. So is it possible to do something like the following? declare const

Declare variable syntax invalid in MySQL Workbench?

北城余情 提交于 2020-07-18 08:56:04
问题 I am trying to create and set a variable: DECLARE myId INT; SET myId = 5; However, I am getting invalid syntax complaint in MySQL Workbench: SQL syntax error near 'DECLARE myId INT;' I have tried the following variants: DECLARE myId INT(4); SET myId = 5; DECLARE @myId INT; SET @myId = 5; DECLARE @myId INT(4); SET @myId = 5; What is wrong? 回答1: As in the comment says Declare is only valid into stored programs like procedures, functions. here you have an example of a store procedure and its

Declare variable in if statement (ANSI C)

不问归期 提交于 2020-06-25 06:41:49
问题 Is there any way to declare variable in if statement (using ANSI C only) ? Example: if(int variable = some_function()) { return 1; } 回答1: No, you cannot do that. What you can do is create a block just for the if { int variable; variable = some_function(); if (variable) return 1; } /* variable is out of scope here */ Note that for this simple case you can call the function as the condition of the if (no need for an extra variable) if (some_function()) return 1; 来源: https://stackoverflow.com

Is it ok to define the loop variable inside the loop's parantheses?

妖精的绣舞 提交于 2020-05-15 19:26:08
问题 I am quite new to C but have a lot of experience in C#. My college instructor told me that in "pure" C, it is wrong to initialize the loop variable inside the loops parantheses. He said that it runs because of the VS compiler. For some reasons, all the material in the presentation also shows loops with their loop variable declared outside the parantheses. for (int i=0; i < 5; i++) { //He says that this is wrong, and you will lose points in tests for that } int i; for (i=0; i < 5; i++) { /

Is it ok to define the loop variable inside the loop's parantheses?

泄露秘密 提交于 2020-05-15 19:26:03
问题 I am quite new to C but have a lot of experience in C#. My college instructor told me that in "pure" C, it is wrong to initialize the loop variable inside the loops parantheses. He said that it runs because of the VS compiler. For some reasons, all the material in the presentation also shows loops with their loop variable declared outside the parantheses. for (int i=0; i < 5; i++) { //He says that this is wrong, and you will lose points in tests for that } int i; for (i=0; i < 5; i++) { /

SQL Setting Variable for Current Year Month by Combining two VarChar fields using case statement

ぃ、小莉子 提交于 2020-04-18 05:18:00
问题 I am trying to declare a variable for the current year and month based on a field called YEARMO. It's a 6 character varchar field with the first 4 characters representing the year and the next 2 characters representing the month (ex. February 2018 as 201802). I need the month variable to have a 0 in front of it if is a month that only has one digit (any month before October). Current code returns '20182' and would like it to return '201802'. declare @current_month varchar(6) set @current

MySQL declare语句用法介绍

╄→гoц情女王★ 提交于 2020-03-10 14:12:50
MySQL数据库中,declare语句是在复合语句中声明变量的指令,下文介绍几个declare语句的应用例子,以供参考。 MySQL declare语句是我们经常用到的语句,下文举例说明了MySQL declare语句的用法,希望对日后学习使用MySQL declare语句的使用能有所帮助。 MySQL declare语句是在复合语句中声明变量的指令。 (1)Example with two DECLARE statements 两个DECLARE语句的实例 CREATE PROCEDURE p8 () BEGIN DECLARE a INT; DECLARE b INT; SET a = 5; SET b = 5; INSERT INTO t VALUES (a); SELECT s1 * a FROM t WHERE s1 >= b; END; // /* I won't CALL this */ 在过程中定义的变量并不是真正的定义,你只是在BEGIN/END块内定义了而已(译注:也就是形参)。注意这些变量和会话变量不一样,不能使用修 饰符@你必须清楚的在BEGIN/END块中声明变量和它们的类型。变量一旦声明,你就能在任何能使用会话变量、文字、列名的地方使用。 (2)Example with no DEFAULT clause and SET statement

What is the correct way to declare and define a FileSystemObject object on VBA?

微笑、不失礼 提交于 2020-01-12 11:03:11
问题 I was reading about how to declare FileSystemObjects objects and I found confusing information. Is it because there are different ways to declare it? I let you some of the ways I found to declare and define FileSystemOjbect objects: Dim FSO As FileSystemObject Set FSO = New FileSystemObject Dim FSO As New FileSystemObject Dim FSO As Object Set FSO = CreateObject("scripting.filesystemobject") Which is the right way to declare FileSystemObject objects? 回答1: All 3 ways are correct. You have hit

MySQL local variables

守給你的承諾、 提交于 2020-01-12 02:29:15
问题 I am trying to define and initialize a MySQL variable for a query. I have the following: declare @countTotal int; SET @countTotal = select COUNT(*) from nGrams; I am using MySQL in Netbeans and it tells me I have an error. What/where is my error? How can I fix this? 回答1: MySQL has two different types of variable: local variables (which are not prefixed by @ ) are strongly typed and scoped to the stored program block in which they are declared. Note that, as documented under DECLARE Syntax: