Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve getInput types #929

Open
wants to merge 267 commits into
base: master
Choose a base branch
from

Conversation

Ethan-Arrowood
Copy link

getInput throws when required is set to true. This commit improves the typing to reflect that.

stephenmichaelf and others added 30 commits November 15, 2017 10:09
…ent-version

Add TFS 2017 Update 3 agent version.
Deep Dive on Building Custom Build or Deploy Tasks
* Add task.json schema file

* Allow any "connectedService:" type of input

* Added the "id" field
Properly escape property value to handle non string types
* Error on multiline secret

* v2.3.0
…t#325)

* Update dependencies to prevent warnings during npm install.

* Remove package-lock until we fully upgrade.
* Add supported commands to TaskLibAnswers

* Remove stray semicolon

* Typescript -> TypeScript
* Revert updates to dependency versions.

* Add package-lock.json.

* Remove root package lock.

* Try to get node_modules output.

* Cleanup.

* Fix make.ks.

* Add third party notice generator.

* Update docs.

* Add third party notice.

* Copy node_modules to _build.

* Copy ThirdPartyNotices.txt to _build directory.

* Prune dev dependencies in _build.

* Remove node_modules copy, shouldn't need to be there.

* Cleanup.

* Clean.

* Clean.
…FileAndTool

Add option to pipe to file and another tool
SvetlanaMaliugina and others added 24 commits May 17, 2022 12:50
* added formatted proxy URL
* version increment
Co-authored-by: microsoft-github-policy-service[bot] <77245923+microsoft-github-policy-service[bot]@users.noreply.github.com>
Co-authored-by: Konstantin Tyukalov <52399739+KonstantinTyukalov@users.noreply.github.com>
…t#848)

* Update pipeline

* Update azure-pipelines.yml

* nodeversion as variable

Co-authored-by: Andrey Ivanov <v-andivanov@microsoft.com>
Co-authored-by: Andrey Ivanov <v-andivanov@microsoft.com>
…ted agent, or not. (microsoft#869)

* Added function getAgentMode

* Function getAgentMode added to documentation

* Fix of documentation
* Updated PSLIB_InvalidPattern0 to be more readable

* Update LegacyFindFunctions.ps1

Co-authored-by: Kirill Ivlev <102740624+kirill-ivlev@users.noreply.github.com>
* Added localization pipeline and LocProject.json

* Removed en-US

* Update localize-pipeline.yml for Azure Pipelines

* Update localize-pipeline.yml for Azure Pipelines

* Made letter case consistent for languages

* LEGO: check in for Localization to temporary branch. (microsoft#703)

* LEGO: check in for Localization to temporary branch. (microsoft#714)

* LEGO: check in for Localization to temporary branch. (microsoft#720)

* Temp renaming

* Renamed localization files

* Applied enhancements for the localization pipeline (microsoft#733)

[skip ci]

* [Localization] Fixed localization pipeline issue with already localized strings replaced (microsoft#737)

* Localized file check-in by OneLocBuild Task: Build definition ID 10947: Build ID 14646607

Localized file check-in by OneLocBuild Task

* LEGO: check in for Localization to temporary branch. (microsoft#740)

* LEGO: check in for Localization to temporary branch. (microsoft#741)

* LEGO: check in for Localization to temporary branch. (microsoft#742)

* LEGO: check in for Localization to temporary branch. (microsoft#743)

* Temporary renamed files - to resolve conflicts

* Temporary renamed

* LEGO: check in for Localization to temporary branch. (microsoft#745)

Co-authored-by: csigs <csigs@outlook.com>

* LEGO: check in for Localization to temporary branch. (microsoft#746)

Co-authored-by: csigs <csigs@outlook.com>

* LEGO: check in for Localization to temporary branch. (microsoft#747)

Co-authored-by: csigs <csigs@outlook.com>

* LEGO: check in for Localization to temporary branch. (microsoft#748)

Co-authored-by: csigs <csigs@outlook.com>

* Localized file check-in by OneLocBuild Task: Build definition ID 10947: Build ID 14905562

Localized file check-in by OneLocBuild Task

* Returned back original names

* Removed redundant locale - test

* Removed redundant folders

* Localized file check-in by OneLocBuild Task: Build definition ID 10947: Build ID 14906155

Localized file check-in by OneLocBuild Task

* Returned back changes. Removed redundant

* Create PR in OneLocBuild task only on third week of sprint (microsoft#755)

* Fix localization pipeline

* Add missed change

* Added option to disable PR creation

* Add OneLocBuild removal to the localization pipeline (microsoft#804)

* Add OneLocBuild removal to the pipeline

* fix ignore error to double if

Co-authored-by: Ilya Kuleshov <v-ikuleshov@microsoft.com>

* Localization update (microsoft#802)

* Removing Localize folder

* Revert "Removing Localize folder"

Co-authored-by: Ilya Kuleshov <v-ikuleshov@microsoft.com>

* Removed OneLocBuild folder

* Move notifications about Task-lib Localization PR from Slack to MS Teams - Part 1 (microsoft#816)

* Localized file check-in by OneLocBuild Task: Build definition ID 10947: Build ID 18673037 (microsoft#879)

* Juno: check in to lego/hb_a4aa9cc4-603b-418e-91f1-700184175625_20221105085105779. (microsoft#881)

* Juno: check in to lego/hb_a4aa9cc4-603b-418e-91f1-700184175625_20221106085044954. (microsoft#882)

* Localized file check-in by OneLocBuild Task: Build definition ID 10947: Build ID 18697074 (microsoft#883)

* Update LocProject file

* Update LocProject

* Remove lowercase loc strings on windows

* Removing Localize and OneLocBuild folder

Co-authored-by: Anatolii Bolshakov (Akvelon INC) <v-anbols@microsoft.com>
Co-authored-by: csigs <csigs@users.noreply.github.com>
Co-authored-by: Egor Bryzgalov <v-egbryz@microsoft.com>
Co-authored-by: Anatoly Bolshakov <anatoly.bolshakov@akvelon.com>
Co-authored-by: csigs <csigs@outlook.com>
Co-authored-by: Nikita Ezzhev <v-niezz@microsoft.com>
Co-authored-by: kuleshovilya <87485027+kuleshovilya@users.noreply.github.com>
Co-authored-by: Ilya Kuleshov <v-ikuleshov@microsoft.com>
Co-authored-by: Denis Tikhomirov <90906678+denis-tikhomirov@users.noreply.github.com>
Co-authored-by: Maksim Petrov <v-mpetrov@microsoft.com>
* Pipeline fixing

* Indentation fix

* Formating

* Node version was reverted
* Migrating to Node 16 (microsoft#844)

* create new release/4.x branch

* release for 4 version

* update pipeline

* update package.json

* fix test and build commands

* fixed tests on node18

* change image version for linux

* fix test for linux

* add separete test for linux

* node v16.13

* add v16.13.0 to test

* test on windows-2022, macOS-11

* separate branch for node16

* remove temporary code

* update package.json

* changed pipeline

* updated pipeline

* Microsoft mandatory file (microsoft#839)

* Update pipeline to include a step for publishing artifacts. (microsoft#848) (microsoft#849)

* Update pipeline

* Update azure-pipelines.yml

* nodeversion as variable

* Added node16 to schema (microsoft#852)

Co-authored-by: Andrey Ivanov <v-andivanov@microsoft.com>

* bump version (microsoft#862)

Co-authored-by: Andrey Ivanov <v-andivanov@microsoft.com>

* Update ci-cd for publishing npm package (microsoft#863)

* fix npm publish

Co-authored-by: Andrey Ivanov <v-andivanov@microsoft.com>

* fix add registry (microsoft#864)

Co-authored-by: Andrey Ivanov <v-andivanov@microsoft.com>

* fix ToolRunner - _getSpawnSyncOptions (microsoft#873)

* Mockery version is updated from 1.7.0 to 2.1.0 because of vulnerability (microsoft#878)

* Fixed release path (microsoft#888)

* Improvement of the release condition (microsoft#889)

* Added test task with test condition. Negative test

* Added test task with test condition. Positive test

* Fix path

* Fix path

* Fix path

* Changed build.sourcebranchname -> build.sourcebranch and path to branch

* Fix path

* Version changed (microsoft#894)

* Pipeline fixing (microsoft#893)

* Token test

* Test token

* Publish test

* call order changed

* Nmp token syntax reverted

* Changed windows job

* Script clearing

* Uncommented condition

* Token changed

* Test - off publish condition

* Switched on publish condition

* Package version was reverted

* Add escape for more correct working

* Add changelog

* Update package-lock version

* Bump tl version to 4.1.0

* Update changelog

* Remove PS task lib changes from node changelog

* Update changelog for 4.0.1-preview

Co-authored-by: AndreyIvanov42 <93121155+AndreyIvanov42@users.noreply.github.com>
Co-authored-by: Andrey Ivanov <v-andivanov@microsoft.com>
Co-authored-by: Denis Rumyantsev <mr.denis.rumyantsev@gmail.com>
Co-authored-by: Roman-Shchukin <111063382+Roman-Shchukin@users.noreply.github.com>
The event "unhandledRejection" was added on process.on because when Promise is rejected and there is no catch
the error will not be thrown and process.on('uncaughtException') won't call for Node10 but it will emit "uncaughtException" for node 16.
So we need to listen to "unhandledRejection" and throw the error to make sure the error is thrown and the result will be similar.
* Improve types for argIf command

* Bump package version

* Update changelog
…s 6.9.4. Severity: High #4370 (microsoft#924)

- Bumped qs version
* Remove note about v4 task lib status

* Fix formatting
`getInput` throws when `required` is set to `true`. This commit improves the typing to reflect that.
node/task.ts Outdated
@@ -238,6 +238,7 @@ export interface VariableInfo {
* @param required whether input is required. optional, defaults to false
* @returns string
*/
export function getInput(name: string, require: true): string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function has a second argument which is optional and its name is required but you had overloaded require argument with true type.
Could you provide cases that you want to handle for a better understanding?
Why did you use true as a type?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a spelling mistake; I'll fix that momentarily.

The type results in a better UX:

Given the code

const foo = getInput('foo', true); 

Currently, foo would be typed as string | undefined, but if the input 'foo' is actually undefined, getInput will throw an error. So actually, the variable foo should have a type of string here, not undefined.

The overload accomplishes this by stating that the type literal true should have a return type of string explicitly. Meanwhile, the catch-all overload satisfies the alternate condition:

const bar = getInput('bar');
// or
const fuzz = getInput('fuzz', false);

Where neither of these calls to getInput will throw an error if the input isn't found; thus, the resulting type for bar or fuzz should be string | undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.